codeforces Round630 div2
阿新 • • 發佈:2022-05-11
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;
}
沒參賽就先補到這吧,英語有點弱。