1.刷题
#include<iostream>
using namespace std;
int main(){int n,m,a;cin>>n>>m;if(n%m!=0){a=n/m+1;}if(n%m==0){a=n/m;}cout<<a;
}
2.染色
#include<iostream>
#include<algorithm>
using namespace std;
long long a[300010];
int main(){int n;cin>>n;for(int i=0;i<n;i++){cin>>a[i];}long long x=1;sort(a,a+n);for(int i=0;i<n;i++){x=x*(a[i]-i)%1000000007;}cout<<x;
}
3.数根(二)
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int f(string x){int sum=0;for(int i=0;i<x.size();i++){sum =sum+x[i]-'0';}return sum;
}
vector<int> div(vector<int> &A,int B,int &r){vector<int> C;for(int i=0;i<A.size();i++){r=r*10+A[i];C.push_back(r/B);r=r%B;}reverse(C.begin(),C.end());while(C.size()>1&&C.back()==0) C.pop_back();return C;
}
int main(){string x;cin>>x;vector<int> A,C;for(int i=0;i<x.size();i++) A.push_back(x[i]-'0');int B=f(x),r=0;C = div(A,B,r);if(r==0){cout<<"Yes";}else{cout<<"No";}
}
4.攻击的车
#include<iostream>
#include<algorithm>
using namespace std;
int a[1000010],b[1000010];
int main(){long long r,c,n;cin>>r>>c>>n;for(int i=0;i<n;i++){cin>>a[i]>>b[i];}sort(a,a+n);sort(b,b+n);long long p=0,q=0;for(int i=0;i<n;i++){if(a[i]!=a[i-1]){p++;}}for(int i=0;i<n;i++){if(b[i]!=b[i-1]){q++;}}cout<<p*c+q*r-p*q;
}
5.推箱子
#include<iostream>
#include<algorithm>
using namespace std;
int main(){int t;cin>>t;while(t--){int o;cin>>o;string s;cin>>s;int x=0;for(int i=0;i<s.size();i++){if(s[i]=='@'){x++;}}if(x==1){cout<<0<<endl;break;}int y=(x+1)/2;int li,ri;for(int i=0;i<s.size();i++){if(s[i]=='@'){y--;if(y==0){li=i;ri=i;break;}}}int l=li,r=ri;int sum=0;while(l>=0){l--;if(s[l]=='@'){sum+=abs(li-l)-1;li--;}}while(r<s.size()){r++;if(s[r]=='@'){sum+=abs(ri-r)-1;ri++;}}cout<<sum<<endl;}
}