分析:注意两个点之间的倍数差,若为偶数则为YES,否则为NO
1 #include "iostream" 2 #include "cstdio" 3 #include "cstring" 4 #include "string" 5 #include "cmath" 6 using namespace std; 7 int main() 8 { 9 int x1,y1,x2,y2; 10 cin>>x1>>y1>>x2>>y2; 11 int x,y; 12 cin>>x>>y; 13 int cnt1=x2-x1; 14 int cnt2=y2-y1; 15 int flag=0; 16 if(cnt1%x){ 17 flag=1; 18 } 19 if(cnt2%y){ 20 flag=1; 21 } 22 if(abs(abs(cnt1/x)-abs(cnt2/y))%2){ 23 flag=1; 24 } 25 if(!flag){ 26 cout<<"YES"<<endl; 27 }else{ 28 cout<<"NO"<<endl; 29 } 30 }
分析:先看只用第一个数是否满足情况,如果不行在加入第二个数,不行在加入第三个数,如此分别统计三种情况即可
1 #include "iostream" 2 #include "cstdio" 3 #include "cstring" 4 #include "string" 5 #include "algorithm" 6 #include "set" 7 #include "vector" 8 using namespace std; 9 const int maxn=100000+10; 10 long long a[maxn]; 11 int n; 12 long long solve3(long long sum){ 13 return (sum*(sum-1)*(sum-2)/6); 14 } 15 long long solve2(long long sum){ 16 return (sum*(sum-1)/2); 17 } 18 int main() 19 { 20 cin>>n; 21 for(int i=0;i<n;i++) 22 cin>>a[i]; 23 sort(a,a+n); 24 set<long long>h; 25 for(int i=0;i<n;i++){ 26 h.insert(a[i]); 27 } 28 set<long long>::iterator it; 29 vector<long long>q; 30 for(it=h.begin();it!=h.end();it++){ 31 q.push_back(*it); 32 } 33 long long cnt1=0,cnt2=0,cnt3=0; 34 for(int i=0;i<n;i++){ 35 if(a[i]==q[0]){ 36 cnt1++; 37 }else if(a[i]==q[1]){ 38 cnt2++; 39 }else if(a[i]==q[2]){ 40 cnt3++; 41 } 42 } 43 if(cnt1>=3){ 44 cout<<solve3(cnt1)<<endl; 45 }else if(cnt1==2){ 46 cout<<cnt2<<endl; 47 }else{ 48 if(cnt2>=2){ 49 cout<<solve2(cnt2)<<endl; 50 }else{ 51 cout<<cnt3<<endl; 52 } 53 } 54 return 0; 55 }
分析:因为两个数的差值最大不会超过18*9=162,所以直接暴力即可
1 #include "iostream" 2 #include "cstdio" 3 #include "cstring" 4 using namespace std; 5 long long a,b; 6 long long solve(long long num){ 7 long long ans=0; 8 while(num){ 9 long long mod=num%10; 10 ans+=mod; 11 num/=10; 12 } 13 return ans; 14 } 15 int main() 16 { 17 cin>>b>>a; 18 long long sum=b-a; 19 if(sum<=0){ 20 cout<<"0"<<endl; 21 return 0; 22 } 23 long long cnt=0; 24 if(b-a<=162){ 25 for(long long i=a;i<=b;i++){ 26 long long tt=i; 27 //cout<<b-solve(tt)<<endl; 28 if((i-solve(tt))>=a) 29 cnt++; 30 } 31 cout<<cnt<<endl; 32 }else{ 33 for(long long i=a;i<=a+162;i++){ 34 long long yy=i; 35 if((i-solve(yy))<a) 36 cnt++; 37 } 38 cout<<sum-cnt+1<<endl; 39 } 40 return 0; 41 }