2.装进肚子
https://ac.nowcoder.com/acm/contest/19850/B
#include<iostream> #include<algorithm> #include<vector> using namespace std; typedef struct node{ int a; int b; }NUM; bool cmp(NUM t,NUM y){ return t.a-t.b>y.a-y.b; } int main(){ NUM p[100005]; int n,k; long long ans=0; cin>>n>>k; for(int i=0;i<n;i++){ cin>>p[i].a; } for(int i=0;i<n;i++){ cin>>p[i].b; } sort(p,p+n,cmp); for(int i=0;i<k;i++){ ans+=p[i].a; } for(int i=k;i<n;i++){ ans+=p[i].b; } cout<<ans<<endl; return 0; }
3. 牛牛的三角形
https://ac.nowcoder.com/acm/contest/19850/C
#include<bits/stdc++.h> using namespace std; int main(){ int n,flag=0; cin>>n; vector<int> a; for(int i=0;i<n;i++){ int e; cin>>e; a.push_back(e); } for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ for(int k=0;k<n;k++){ if(i!=j&&j!=k&&k!=i){ if(a[i]+a[j]>a[k]&&abs(a[i]-a[j])<a[k]){ flag=1; cout<<a[i]<<" "<<a[j]<<" "<<a[k]<<endl; break; } } } if(flag) break; } if(flag) break; } if(!flag) cout<<"No solution\n"; return 0; }
4.[NOIP1998]拼数
https://ac.nowcoder.com/acm/contest/19850/D
#include<bits/stdc++.h> using namespace std; bool cmp(string a,string b){ return a+b>b+a; } int main(){ string s[25]; int n; cin>>n; for(int i=0;i<n;i++){ cin>>s[i]; } sort(s,s+n,cmp); for(int i=0;i<n;i++){ cout<<s[i]; } cout<<endl; return 0; }
5.