Codeforces Round #654 (Div. 2) A~D

题目链接

A、Magical Sticks

思维题,找找规律即可。

#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define ll long long
using namespace std;
int main(){
    
    
    ll n,t;
    cin >> t;
    while(t--)
    {
    
    
        cin >> n;
        if(n==1||n==2)
            cout << 1 <<endl;
        else if(n%2==0)
            cout << n/2 <<endl;
        else
            cout << n/2+1 <<endl;
    }
    return 0;
}

B、Magical Calendar

思维题,找找规律即可。

#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define ll long long
using namespace std;
int main(){
    
    
    ll n,t,k;
    cin >> t;
    while(t--)
    {
    
    
        cin >> n >> k;
        if(k>=n)
            cout << n*(n-1)/2 + 1 <<endl;
        else
            cout << k*(k+1)/2 <<endl;
    }
    return 0;
}

C、A Cookie for You

这个题要优先考虑第二类客人,因为第一类客人优先吃多的饼干,第二类客人优先吃少的饼干,首先看饼干总数量够不够,如果够则查看少的饼干是否能够第二类客人吃,不够则No,够了则Yes

#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define ll long long
using namespace std;
int main(){
    
    
    ll n,t,a,b,m;
    cin >> t;
    while(t--)
    {
    
    //a个香草b个巧克力n个1类m个2类
        cin >> a >> b >> n >> m;
        if(a+b<n+m)
            cout << "No" <<endl;
        else{
    
    
            if(min(a,b)>=m)
                cout << "Yes" <<endl;
            else
                cout << "No" <<endl;
        }
    }
    return 0;
}

D、Grid-00100

当k能被n整除时,是可以使得每一行每一列个数相同的,如果有余数的话,把余数错开放在每行后面一个1,可以使得满足1+1=2 的情况的。
具体看代码

#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define ll long long
using namespace std;
const int maxn=305;
int n,k,t;
int a[maxn][maxn];
int main () {
    
    
    cin >> t;
    while (t--) {
    
    
    	cin >> n >> k;
    	if (k%n==0) 
    	    cout << 0 <<endl;
    	else 
    	    cout << 2 <<endl;
   	int tt=0;
    	memset(a,0,sizeof(a));
    	for (int i=1;i<=k/n;i++) {
    
    
   	    for (int j=0;j<n;j++)
                a[j][(j+tt)%n]=1;
  	    tt++;
        }
        if (k%n)
    	    for (int i=0;i<k%n;i++)
           	a[i][(i+tt)%n]=1;
    	for (int i=0;i<n;i++) {
    
    
   	    for (int j=0;j<n;j++)
           	 cout << a[i][j];
   	    cout <<endl;
   	}
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_45949914/article/details/107095839