题目链接:http://codeforces.com/contest/1113
第一题(简单数学):
#include<bits/stdc++.h>
using namespace std;
#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define ll long long
#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define root l,r,rt
#define mst(a,b) memset((a),(b),sizeof(a))
#define pii pair<int,int>
#define fi first
#define se second
#define mk(x,y) make_pair(x,y)
const int mod=1e9+7;
const int maxn=4e5+10;
const int ub=1e6;
const double inf=1e-4;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
int n,m;
int main(){
cin>>n>>m;
int lft=n-1,cur=0;
if(lft<=m) cout<<lft<<endl;
else{
lft-=m;
cout<<m+lft*(lft+1)/2+lft<<endl;
}
return 0;
}
第二题(贪心+暴力枚举):
#include<bits/stdc++.h>
using namespace std;
#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define ll long long
#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define root l,r,rt
#define mst(a,b) memset((a),(b),sizeof(a))
#define pii pair<int,int>
#define fi first
#define se second
#define mk(x,y) make_pair(x,y)
const int mod=1e9+7;
const int maxn=5e5+10;
const int ub=1e6;
const double inf=1e-4;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
int a[maxn];
int n,x,sum=0,ans=0;
int main(){
cin>>n;
rep(i,0,n) {cin>>a[i];sum+=a[i];}
sort(a,a+n);
ans=sum;
rep(i,1,n) for(int j=2;j*j<=a[i];j++) if(a[i]%j==0){
ans=min(ans,sum-a[i]-a[0]+a[0]*j+a[i]/j);
int tp=a[i]/j;
ans=min(ans,sum-a[0]-a[i]+a[0]*tp+a[i]/tp);
}
cout<<ans<<endl;
return 0;
}
第三题(异或性质):
#include<bits/stdc++.h>
using namespace std;
#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define ll long long
#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define root l,r,rt
#define mst(a,b) memset((a),(b),sizeof(a))
#define pii pair<int,int>
#define fi first
#define se second
#define mk(x,y) make_pair(x,y)
const int mod=1e9+7;
const int maxn=1<<21;
const int ub=1e6;
const double inf=1e-4;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
int cnt[2][maxn];
int n,x,a,Max;
int main(){
cin>>n;
cnt[0][0]++,x=Max=0;
rep(i,1,n+1){
cin>>a;
x^=a;
cnt[i&1][x]++;
Max=max(a,Max);
}
Max<<=1;
ll ans=0;
rep(i,0,2) rep(j,0,Max+1) if(cnt[i][j])
ans+=1LL*cnt[i][j]*(cnt[i][j]-1)/2;
cout<<ans<<endl;
return 0;
}
第四题(构造+情况完备性考虑T_T):
#include<bits/stdc++.h>
using namespace std;
#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define ll long long
#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define root l,r,rt
#define mst(a,b) memset((a),(b),sizeof(a))
#define pii pair<int,int>
#define fi first
#define se second
#define mk(x,y) make_pair(x,y)
const int mod=1e9+7;
const int maxn=5e3+10;
const int ub=1e6;
const double inf=1e-4;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
char s[maxn];
int judge(int x){
if(x&1) return 0;
int l=1,r=x,mark=1;
while(l<r) {if(s[l]!=s[r]) mark=0;l++,r--;}
if(mark){
mark=0;
rep(i,1,x/2+1) if(s[i]!=s[x/2+i])
{mark=1;break;}
}
if(mark) return 1;
return judge(x/2);
}
int main(){
scanf("%s",s+1);int len=strlen(s+1);
int flag=len&1,mark=0;
for(int i=2;i<=len/2;i++) if(s[i]!=s[i-1]) {mark=1;break;}
if(mark==0) puts("Impossible");
else{
if(len%2==0){
int ret=1;
rep(i,1,len/2+1) if(s[i]!=s[i+len/2])
{ret=0;break;}
if(ret==0) puts("1");
else{
if(judge(len/2)) puts("1");
else puts("2");
}
}
else{
if(judge(len/2)) puts("1");
else puts("2");
}
}
return 0;
}