【CF #777 div2】A—D

A. Madoka and Math Dad

题解:拆分成2、1。找到能生成的最大值即可。

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+7;
int a[maxn];
#define sc scanf
#define pr printf
int pos[40];
 
void ff(int x){
	for(int i=0;i<32;i++){
		if(x>>i&1) pos[i]++;
	}
} 
int main() {
	int t;cin>>t;
	while(t--){
		int n;cin>>n;
		int k=n%3;
		if(n==1)pr("1");
		else if(n==2)pr("2");
		else if(k==2){
			int sum=2;
			pr("2");
			while(sum<n){
				pr("12");
				sum+=3;
			}
		}else if(k==1){
			int sum=1;
			pr("1");
			while(sum<n){
				pr("21");
				sum+=3;
			}
		}
		else {
			int sum=0;
			while(sum<n){
				pr("21");
				sum+=3;
			}
		}
		pr("\n");
	}
	return 0;
}

B. Madoka and the Elegant Gift

题解:还是有点弄不清题意。总之就是把如果存在相邻四个格子(四个方向)只存在三个为黑色则满足题意。

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+7;
#define ll long long
string a[maxn];
#define sc scanf
#define pr printf
int main() {
	int t;cin>>t;
	while(t--){
		int n,m;cin>>n>>m;
		int f=0;
		for(int i=0;i<n;i++)cin>>a[i];
		for(int i=0;i<n;i++)
		   for(int j=0;j<m;j++){
		   	    int sum=0; 
		   		sum+=a[i][j]-'0';
		   		if(i+1<n)sum+=a[i+1][j]-'0';
		   		if(j+1<m)sum+=a[i][j+1]-'0';
		   		if(i+1<n&&j+1<m)sum+=a[i+1][j+1]-'0';
		   		if(sum==3){
		   			f=1;break;
				   }
			   if(f)break;
		   }
		if(f==0)pr("YES\n");
		else pr("NO\n");
	}
	return 0;
}

C. Madoka and Childish Pranks

题意:如何按棋盘格的格式填成所需格式,不得填成则输出-1

题解:
我们只用两种格式,即横向和纵向的【白黑】
然后先从右向左填满第一排,然后从右下角往左上角填即可。第一个位置可能会出现不符合题意的时候。

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e3+7;
#define ll long long
string a[maxn];
#define sc scanf
#define pr printf
struct one{
	int x1,x2,x3,x4;
}an[10000+3];
int main() {
	int t;cin>>t;
	while(t--){
		int n,m;cin>>n>>m;
		int f=1;
		int qwq=0;
		for(int i=0;i<n;i++)cin>>a[i];
		if(a[0][0]=='1') {f=0;goto ans;}
		for(int j=m-1;j>0;j--)if(a[0][j]=='1')an[qwq++]={1,j,1,j+1};
		for(int i=n-1;i>0;i--){
		   for(int j=m-1;j>0;j--)
		   { 
		      if(a[i][j]=='1')
		      an[qwq++]={i+1,j,i+1,j+1};
			}
		   if(a[i][0]=='1')an[qwq++]={i,1,i+1,1};
		}
		ans:
		if(!f)pr("-1\n");
		else {
		   pr("%d\n",qwq);
		   for(int i=0;i<qwq;i++)pr("%d %d %d %d\n",an[i].x1,an[i].x2,an[i].x3,an[i].x4);
		}
	}
	return 0;
}

D. Madoka and the Best School in Russia

题意:
题目定义了两种数:
good:d的倍数
beautiful:good乘以一个非good
要求判断某数字是不是由一个或多个相乘得来的。

题解:
可以推出beautiful这个数会满足:x%d=0&&x%d2!=0
所以n(判断数字)=dkp
【1】k等于0、1
不满足题意
【2】k等于2
p是合数,则满足(p=xy,n=dxdy)
【3】k等于3
p是合数,则满足
p是素数,d是合数,且d!=p
p,满足。
【4】k大于3
p是合数,满足。
p是素数,d是合数,满足。

By Dawn0211, contest: Codeforces Round #777 (Div. 2), problem: (D) Madoka and the Best School in Russia, Accepted, #, Copy
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e3+7;
#define ll long long
string a[maxn];
#define sc scanf
#define pr printf
bool prime(int x){
	if(x == 1)
		return true;
	for(int i = 2;i <= x/i;i++){
		if(x%i == 0){
			return false;
		}
	}
	return true;
}
int main() {
	int t;cin>>t;
	while(t--){
		int n,d;cin>>n>>d;
		int k=0;//记录d
		while(n%d==0){
			k++;
			n/=d;
		}
		if(k==0||k==1)cout<<"no\n";
		else if(k==2){
			if(!prime(n))cout<<"yes\n";
			else cout<<"no\n";
		} 
		else if(k==3){
			if(!prime(n))cout<<"yes\n";
			else{
				if(!prime(d)&&(ll)n*n!=d)cout<<"yes\n";
				else cout<<"no\n";
			}
		}
		else {
			if(!prime(n))cout<<"yes\n";
			else if(!prime(d))cout<<"yes\n";
			else cout<<"no\n";
		}
	}
	return 0;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值