贪心凑长度为 n n n的木棒
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0) #include<iostream> #include<algorithm> using namespace std; int n; int main() { IO; int T; cin>>T; while(T--) { cin>>n; cout<<(n+1)/2<<endl; } return 0; }仔细分析一下这个题分两种情况就可以了(毕竟数据范围那么大)
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0) #include<iostream> #include<algorithm> using namespace std; typedef long long ll; ll n,r; int main() { IO; int T; cin>>T; while(T--) { cin>>n>>r; ll res; if(n>r) res=1ll*(1+r)*r/2; else res=1ll*n*(n-1)/2+1; cout<<res<<endl; } return 0; }第三题读题读蒙了。。最后发现第一种人很听话有东西就可以吃,所以尽可能先满足第二种人就可
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0) #include<iostream> #include<algorithm> using namespace std; typedef long long ll; ll a,b,n,m; int main() { IO; int T; cin>>T; while(T--) { cin>>a>>b>>n>>m; if(n+m>a+b) cout<<"No"<<endl; else { if(a>b) { if(b>=m&&a+b-m>=n) cout<<"Yes"<<endl; else cout<<"No"<<endl; } else { if(a>=m&&b+a-m>=n)cout<<"Yes"<<endl; else cout<<"No"<<endl; } } } return 0; }哎~~又是只做了三个题
第四题后来发现只有两种情况,如果学过线性代数应该更容易想(求矩阵行列式时需要找不同行不同列的数,我们就按照那样构造矩阵就行)惭愧学过线代还是没做出来,我tcl
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0) #include<iostream> #include<algorithm> #include<cstring> using namespace std; typedef long long ll; const int N=310; char g[N][N]; int n,k; int main() { IO; int T; cin>>T; while(T--) { cin>>n>>k; memset(g,'0',sizeof g); if(k%n==0) cout<<0<<endl; else cout<<2<<endl; int i=0,j=0; while(k--) { g[i++][j++]='1'; j=j%n; if(i==n) i=0,j++; } for(int i=0;i<n;i++) { for(int j=0;j<n;j++)cout<<g[i][j]; cout<<endl; } } return 0; }先找出数组中最大值 m m m,然后分析可以知道当 x < m − n + 1 x<m-n+1 x<m−n+1时最终肯定不能全部击败,当 x ≥ m x\ge m x≥m时,不管按照任何顺序都能够打完,由于 p ≤ n p\leq n p≤n分析可知 f ( x ) f(x) f(x)一定能够被 p p p整除,取 m − n + 1 ≤ x < m m-n+1\leq x<m m−n+1≤x<m即可,然后根据乘法原理模拟求一下方案数(这里不一定要把方案数求出来,求排列数过程中的因子能被 p p p整除那么该 x x x不满足题目意思,如果因子都不能被 p p p整除那么满足) 时间复杂度 O ( n 2 ) O(n^2) O(n2)
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0) #include<iostream> #include<algorithm> #include<vector> using namespace std; typedef long long ll; const int N=2010; int a[N],n,p; vector<int> ans; int main() { IO; cin>>n>>p; int m=0; for(int i=0;i<n;i++) { cin>>a[i]; m=max(m,a[i]); } sort(a,a+n); for(int x=m-n+1;x<m;x++)//枚举初始的x { int flag=1; int j=0; for(int i=0;i<n-1;i++)//第几轮 { for(j;j<n;j++) if(x+i<a[j]) break;//寻找现在能够打败多少个怪兽 if((j-i)%p==0) //j-i就是能够打败的并且之前没有打过的 { flag=0;//做个标记就可 break; } } if(flag) ans.push_back(x); } cout<<ans.size()<<endl; for(auto t:ans) cout<<t<<" "; cout<<endl; return 0; }