codeforces #332 div2
A.
#include<cstdio> #include<algorithm> #include<cmath> #include<map> #include<iostream> #include<vector> #include<cstring> #include<queue> #include<string> using namespace std; int a,b,c; int ans1,ans2,ans3; int main() { //freopen("input.txt","r",stdin); cin>>a>>b>>c; int ans1=2*(a+b); int ans2=2*(a+c); int ans3=2*(b+c); int ans4=a+b+c; int w=min(min(ans1,ans2),min(ans3,ans4)); cout<<w<<endl; }
B.
#include<cstdio> #include<algorithm> #include<cmath> #include<map> #include<iostream> #include<vector> #include<cstring> #include<queue> #include<string> using namespace std; int n,m; int ans[100005]; int w[100005]; map<int,int> q; map<int,int>::iterator it; int flag=2; int main() { // freopen("input.txt","r",stdin); int t; scanf("%d%d",&n,&m); for(int i=0;i<n;i++) { scanf("%d",&t); q.insert(pair<int,int>(t,i+1)); ans[t]++; } for(int i=0;i<m;i++) { scanf("%d",&t); it=q.find(t); if(it!=q.end()&&flag!=1) { w[i]=it -> second; if(ans[it->first]>1) flag=0; } else flag=1; } if(flag==1) printf("Impossible\n"); else if(flag==0) printf("Ambiguity\n"); else { printf("Possible\n"); for(int i=0;i<m;i++) printf("%d ",w[i]); } }
C.
贪心:前缀最大值不大于后缀最小值
#include<cstdio> #include<algorithm> #include<cmath> #include<map> #include<vector> #include<iostream> #include<cstring> using namespace std; int a[100005]; int ma[100005]; int mi[100005]; int main() { int n,ans=0; scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); ma[0]=-1; for(int i=1;i<=n;i++) { ma[i]=max(ma[i-1],a[i]); } mi[n+1]=1e9+5; mi[n]=a[n]; for(int i=n-1;i>=1;i--) { mi[i]=min(mi[i+1],a[i]); } for(int i=1;i<=n;i++) { if(ma[i]<=mi[i+1]) ans++; } printf("%d\n",ans); }
D.数学题
f(n,m)=∑k=(n−k+1)(m−k+1)
f(n,m)=(n*n/2+n/2)m+n*n+n−(n+2)(n+1)n/2+n(n+1)(2*n+1)/6
枚举n
#include<cstdio> #include<algorithm> #include<cmath> #include<map> #include<vector> #include<iostream> #include<cstring> using namespace std; typedef long long LL; typedef pair<LL,LL> p; long long n; long long ans,x,y; vector<p>t; int main() { scanf("%I64d",&n); int xx=6*pow(n,1.0/3.0); // printf("%d\n",xx); for(long long i=1;i<=xx;i++) { x=(i*i+i)/2; y=n-i*i-i+(i+2)*(i+1)*i/2-(i+1)*i*(2*i+1)/6; if(y>0&&y%x==0) { ans++; long long dd=y/x; if(dd>=i){ t.push_back(make_pair<LL,LL>(i,dd)); t.push_back(make_pair<LL,LL>(dd,i)); } } } sort(t.begin(),t.end()); int len=unique(t.begin(),t.end())-t.begin(); printf("%d\n",len); for(int i=0;i<len;i++) { printf("%I64d %I64d\n",t[i].first,t[i].second); } }