codeforces Round630 div2

codeforces Round630 div2

[题目链接点击就进去了](https://codeforces.ml/blog/entry/75432)

A

题意:已知一个范围x1,y1,x2,y2,还有初始的位置x,y要走左a步,右b步,上c步,下d步,走过这么多步后如果还在范围内的话,则输出Yes,否则输出No,

题解:左右,上下往返走抵消一部分,然后抵消后看是否还在范围之内。注意特殊情况,就是走不动的情况x1=x2且a,b存在大于0,或y1=y2时,存在c或d大于0,都不存在解

代码:

#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;
int main()
{
	int t;
	cin>>t;
	int a,b,c,d;
	int x,y,x1,y1,x2,y2;
	int tx,ty;
	while(t--){
		int flag=0;
		cin>>a>>b>>c>>d;
		cin>>x>>y>>x1>>y1>>x2>>y2;
		tx = b-a;
		ty = d-c;
		if(x1==x2 && (a>0 || b>0))
			flag=0;
		else if(y1==y2 && (c>0 || d>0))
			flag=0;
		else if(tx+x<=x2 && tx+x>=x1 && ty+y>=y1 && ty+y<=y2)
			flag=1;
		if(flag) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	return 0;
}

B

题意:
给这1000个数染色,要求相同颜色的数的 gcd>1 然后颜色的种类数不能超过11,并且假如你用了m种颜色,那么1~m中的任意一种颜色都要至少被使用一次;

题解:
看数据范围,数据范围是1000,平方小于1000个数分解完,只有11个质因数,31*31=961,将质因数相同的数字分为一类就可以了。

代码:

#include<iostream>
#include<string.h>
using namespace std;
int p[11]={2,3,5,7,11,13,17,19,23,29,31};
int vis[12];
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		int a[1005],color[1005];
		for(int i=0;i<n;i++)
			cin>>a[i];
		memset(vis,0,sizeof(vis));
		int temp=0;
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<11;j++)
			{
				if(a[i]%p[j]==0){
					if(!vis[j])
						vis[j]=++temp;
					color[i]=vis[j];
					break;
				}
			}
		}
		cout<<temp<<endl;
		for(int i=0;i<n;i++)
			cout<<color[i]<<" ";
		cout<<endl;
	}
	return 0;
}

没参赛就先补到这吧,英语有点弱。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值