只会前6.。。。。。。。。。后面太难顶了。。。。。。。。。。。。
A:
四个数分两组使得差就小,肯定就是先排序然后一个小的一个大的拎出来,然后中间的拎出来,相减一下就行了。
代码
#include<bits/stdc++.h> using namespace std; typedef long long int ll; const int maxn = 1e5 + 10; void solved(){ int a[5]; cin>>a[1]>>a[2]>>a[3]>>a[4]; sort(a + 1, a + 5); cout<<abs((a[1] + a[4]) - (a[2] + a[3]))<<endl; } int main(){ solved(); return 0; }
B:
就按照题目要求搞呗,第一第二关键字降序,第三关键字升序,然后输出就行了。
代码
#include<bits/stdc++.h> using namespace std; typedef long long int ll; const int maxn = 1e5 + 10; struct node{ ll date,no; double tem; node(){} node(ll a,ll b,double c):date(a),no(b),tem(c){} }a[maxn]; bool cmp(node a,node b){ if(a.date != b.date )return a.date > b.date; else if(a.tem != b.tem)return a.tem > b.tem; else return a.no < b.no; } void solved(){ int n;cin>>n; int cnt = 0; for(int i = 1; i <= n; i++){ ll x,y;double z;cin>>x>>y>>z; if(z >= 38.0) a[cnt++] = {x,y,z}; } sort(a,a + cnt,cmp); cout<<cnt<<endl; for(int i = 0; i < cnt; i++){ printf("%lld %lld %.1lf\n",a[i].date,a[i].no,a[i].tem); } } int main(){ solved(); return 0; }
C:
一开始想复杂了,想着把所有的子序列全部切割出来,然后从最大的开始比较,不同就直接返回答案就行了,。。。。子序列切割不太会写。。。。后来发现,只要某个序列有一个字符和另外一个不同,那么他们两个的最大长度一定不是另外一个序列的子串,否则就是-1,这样想就直接输出两个串的最大长度就行了。
代码
#include<bits/stdc++.h> using namespace std; typedef long long int ll; const int maxn = 1e4 + 10; char s1[maxn],s2[maxn]; void solved(){ string s1,s2; cin>>s1>>s2; if(s1 == s2)cout<<"-1"<<endl; else cout<<max(s1.size(),s2.size())<<endl; } int main(){ solved(); return 0; }
D:
一开始题意看错了,,,浪费好多时间,0和1的地位是相等的,只要
00
010
0110
不断在两个0中间插入1这样就可以得到满足条件的所有长度串了。
需要特判一下n == 2
代码
#include<bits/stdc++.h> using namespace std; void solved(){ int n;cin>>n; if(n == 1){ cout<<"1"<<endl; cout<<"1"<<endl; return ; } if(n == 2){ cout<<2<<endl; cout<<"0"<<endl; cout<<"11"<<endl;return ; } cout<<n - 1<<endl; cout<<"00"<<endl; for(int k = 3;k <= n; k++){ for(int i = 1; i <= k; i++){ if(i == 1 || i == k)cout<<"0"; else cout<<"1"; } cout<<endl; } } int main(){ solved(); return 0; }
E:
直接贪心选择每次吃美味程度最多的就行,排序一下,因为每吃一个后面的美味程度全部-1,从cnt来计算每次吃完后后面美味程度减少多少。
代码
#include<bits/stdc++.h> using namespace std; typedef long long int ll; const int maxn = 1e5 + 10; ll a[maxn]; bool cmp(ll a,ll b){ return a > b; } void solved(){ int n;cin>>n; for(int i = 1; i <= n; i++)cin>>a[i]; sort(a + 1, a + 1 + n,cmp); ll ans = 0; ll cnt = 0; for(int i = 1; i <= n; i++){ ans += a[i] - cnt; cnt ++; } cout<<ans<<endl; } int main(){ solved(); return 0; }
F:
打表 一下,然后特判一下就好了。。。。。
代码
#include<bits/stdc++.h> using namespace std; int table1[102] = {14, 13,12,11,9,8,14,13,11,10,9, 8,13,12,11,10,8,14,13,12,10, 9,8,14,12,11,10,9,14,13,12, 11,9,8,14,13,11,10,9,8,13, 12,11,10,8,14,13,12,10,9,8, 14,12,11,10,9,14,13,12,11,9, 8,14,13,11,10,9,8,13,12,11, 10,8,14,13,12,10,9,8,14,12, 11,10,9,14,13,12,11,9,8,14, 13,11,10,9,8,13,12,11,10,9 }; int table2[102] ={18 ,17, 16, 15, 20, 19, 18, 17, 15, 21, 20, 19, 17, 16, 15, 21, 19, 18, 17, 16, 21, 20, 19, 18, 16, 15, 21, 20, 18, 17, 16, 15, 20, 19, 18, 17, 15, 21, 20, 19, 17, 16, 15, 21, 19, 18, 17, 16, 21, 20, 19, 18, 16, 15, 21, 20, 18, 17, 16, 15, 20, 19, 18, 17, 15, 21, 20, 19, 17, 16, 15, 21, 19, 18, 17, 16, 21, 20, 19, 18, 16, 15, 21, 20, 18, 17, 16, 15, 20, 19, 18, 17, 15, 21, 20, 19, 17, 16, 15, 21, 20, 19} ; void solved(){ int t; for(scanf("%d",&t);t;t--){ int y,m,d;cin>>y>>m>>d; int year = y; y -= 2000; if(m < 5){ cout<<"Mother's Day: May "<<table1[y]<<"th, "<<year<<endl; }else if(m == 5){ if(d < table1[y]){ cout<<"Mother's Day: May "<<table1[y]<<"th, "<<year<<endl; }else { if(table2[y] == 21) cout<<"Father's Day: June "<<table2[y]<<"st, "<<year<<endl; else cout<<"Father's Day: June "<<table2[y]<<"th, "<<year<<endl; } }else if(m == 6){ if(d < table2[y]){ if(table2[y] == 21) cout<<"Father's Day: June "<<table2[y]<<"st, "<<year<<endl; else cout<<"Father's Day: June "<<table2[y]<<"th, "<<year<<endl; }else { cout<<"Mother's Day: May "<<table1[y + 1]<<"th, "<<year + 1<<endl; } } else if(m > 6)cout<<"Mother's Day: May "<<table1[y + 1]<<"th, "<<year + 1<<endl; } } int main(){ solved(); return 0; }