牛客每日练习----车辆安排,Dominoes,ZQ的睡前故事

我喜欢给自己压力,必须得定一个很高的目标,逼自己朝着这个目标前进,不管会不会实现,都是一个动力。                                      ----喻言

链接:https://ac.nowcoder.com/acm/problem/15912
来源:牛客网
 

题目描述

有n个队伍,每个队伍的人数小于等于5,每辆车最多坐5个人,要求一个队伍的人都在一辆车上,求最少的车数

输入描述:

第一行n
第二行n个数,表示每个队伍的人数

输出描述:

输出最少车数

示例1

输入

复制

3
3 4 5

输出

复制

3

备注:

n≤1e5
每个数小于等于5
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#include<climits>//INT_MAX
#define PP pair<ll,int>
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3fll
#define dinf 1000000000000.0
typedef long long ll;
using namespace std;
int const N=1010;
int const mod=1e9+7;
const int maxn=1e5+10;
int a[10],n,jg,c,m;
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&c);
		a[c]++;
	}
    jg=a[5];
	n-=a[5];
    while(n)
    {
        jg++;
		m=5;
        for(int i=4;i;i--)
            while(a[i]&&m>=i){
                n--;
				m-=i;
				a[i]--;
			}
    }
    printf("%d",jg);
    return 0;
}

链接:https://ac.nowcoder.com/acm/problem/15934
来源:牛客网
 

题目描述

Orz likes to play dominoes. Now giving an n∗m chessboard and k dominoes whose size are 1∗2, Orz finds that there is exactly one grid empty, so that he can move dominoes without overlapping them. An initial situation is given, he wants to know how many final situation could be achieved, except the initial situation. Note every domino is different, as they have their own serial number. Since the answer may be very large, please output the answer modulo 1000000009.

输入描述:

There will be multiple test cases. For each test
case:

The first line contains three integers: n,m,k(n≤9,m≤10000).

The following k lines, each line contains four
integers: a b c d, indicating that this domino occupies (a, b) and (c, d).

The input guarantees that the domino does not
overlap, and there is exactly one empty grid.

输出描述:

For each test cases, output the answer modulo
1000000009.

示例1

输入

复制

5 5 12
1 1 2 1 
1 2 2 2 
1 3 2 3 
1 4 1 5
2 4 2 5
3 4 3 5
3 1 3 2
4 1 4 2
5 1 5 2
4 3 5 3
4 4 5 4
4 5 5 5

输出

复制

8
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#include<climits>//INT_MAX
#define PP pair<ll,int>
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3fll
#define dinf 1000000000000.0
typedef long long ll;
using namespace std;
int const N=1010;
int const mod=1e9+7;
const int maxn=1e5+10;
int n,m,k,mp[10][10010],vis[10][10010];
int fx[4]={-2,2,0,0};
int fy[4]={0,0,-2,2};
struct node
{
    int x;
	int y;
};
bool jc(int x, int y)
{
    if (x<1||x>n||y<1||y>m )
        return false;
    else
        return true;
}
int bfs(int sx , int sy)
{
    memset(vis,0, sizeof(vis));
    node p,q;
    p.x=sx;
    p.y=sy;
    queue<node>Q;
    Q.push(p);
    vis[p.x][p.y]=1;
    while(!Q.empty())
    {
        p=Q.front();
        Q.pop();
        for (int i=0; i<4; i++)
        {
            q.x=p.x+fx[i];
            q.y=p.y+fy[i];
            if (!jc(q.x,q.y)||vis[q.x][q.y])
                continue;
            int xx=p.x+fx[i]/2;
            int yy=p.y+fy[i]/2;
            if (mp[q.x][q.y]!=mp[xx][yy])
               continue;
            vis[q.x][q.y]=1;
            Q.push(q);
        }
    }
    int jg=0;
    for (int i=1; i<=n; i++)
        for (int j=1; j<=m; j++)
            if (vis[i][j]) 
				jg++;
    return jg-1;
}
int main()
{
    while(scanf("%d%d%d",&n,&m,&k)!=EOF)
    {
        memset (mp,0,sizeof(mp));
        for (int i=1;i<=k;i++)
        {
            int a,b,c,d;
            scanf ("%d%d%d%d",&a,&b,&c,&d);
            mp[a][b]=i;
            mp[c][d]=i;
        }
        int sx,sy;
        for (int i=1;i<=n;i++)
            for (int j=1;j<=m;j++)
                if (mp[i][j]==0)
                    sx=i,sy=j;
        printf("%d\n",bfs(sx,sy));
    }
    return 0;
}

链接:https://ac.nowcoder.com/acm/problem/15896
来源:牛客网
 

题目描述

    ZQ是一个拥有n女朋友的万人迷,她的每一个女朋友每天晚上都会挨个给他打电话,要他讲了睡前故事才能睡觉。可是,每次他的女朋友都会挑他在吃鸡的时候打电话,ZQ总是因为挂机被舍友赶出宿舍,于是,ZQ告诉他的女朋友们,别打电话了,他会主动打过去给他们讲故事,再打电话就分手!

    于是,ZQ把他的女朋友名字写在纸上,画成一圈,顺时针编号为1~n,然后从1开始顺时针数。在每一次数数中,ZQ数k个就停下来,然后给选中的女朋友打电话讲故事。 

    现在需要你按顺序告诉我们他给女朋友打电话的顺序

输入描述:

先输入一个t,然后t组数据,每行包含两个数字n,k,n<20,k>0

输出描述:

按顺序输出每轮被选中的女朋友的编号。

示例1

输入

复制

3
10 3
5 2
11 4

输出

复制

3 6 9 2 7 1 8 5 10 4
2 4 1 5 3
4 8 1 6 11 7 3 2 5 10 9
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#include<climits>//INT_MAX
#define PP pair<ll,int>
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3fll
#define dinf 1000000000000.0
typedef long long ll;
using namespace std;
int const N=1010;
int const mod=1e9+7;
const int maxn=1e5+10;
queue<int> q;
int t,n,k;
int main()
{
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&n,&k);
        for(int i=1; i<=n; i++)
            q.push(i);
        while(q.size())
        {
            for(int i=1; i<k; i++)
            {
                q.push(q.front());
                q.pop();
            }
            if(q.size()!=1)
            	printf("%d ",q.front());
            else 
				printf("%d\n",q.front());
            q.pop();
        }
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值