YACS-202105
YACS-202105
整除
http://iai.sh.cn/problem/440
#include<bits/stdc++.h> using namespace std; int n; int a[100002]; bool b[1000002]; int ans; int main(){ cin>>n; for(int i=1;i<=n;i++){ cin>>a[i]; } sort(a+1,a+n+1); for(int i=1;i<=n;i++){ if(a[i]==a[i+1]){//相同数字 int x=a[i]; while(x<=a[n]){//所有数字倍数记录b数组 b[x]=true; x+=a[i]; } //如果是相同,已经标记过了,直接跳 while(a[i]==a[i+1]){ i++; } continue;//相同的保证只累加一次 } if(!b[a[i]]){//不在b数组累加 ans++; } int y=a[i]; //所有数字倍数记录b数组 while(y<=a[n]){ b[y]=true; y+=a[i]; } } cout<<ans; return 0; }
城市的中心
http://iai.sh.cn/problem/444
#include<bits/stdc++.h> using namespace std; int n; int ans; struct poi{ int x,y; }; poi v[200002]; bool cmpx(poi p1,poi p2){ return p1.x<p2.x; } bool cmpy(poi p1,poi p2){ return p1.y<p2.y; } int main(){ cin>>n; for(int i=0;i<n;i++){ cin>>v[i].x>>v[i].y; } sort(v,v+n,cmpx);//按x坐标排序 int xx=v[n/2].x;//取x中间位置 sort(v,v+n,cmpy);//按y坐标排序 int yy=v[n/2].y;//取y中间位置 for(int i=0;i<n;i++){//计算所有距离和 ans+=abs(xx-v[i].x); ans+=abs(yy-v[i].y); } cout<<ans; return 0; }
整除
作者:newcode 更多资源请关注纽扣编程微信公众号

从事机器人比赛、机器人等级考试、少儿scratch编程、信息学奥赛等研究学习

浙公网安备 33010602011771号