Codeforces Beta Round #79 (Div. 2 Only)
http://codeforces.com/contest/102
A
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 13000005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,int>pli;
typedef pair<char,int> pci;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long MOD=1e9+;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int a[][];
int v[]; int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
int n,m;
cin>>n>>m;
for(int i=;i<=n;i++) cin>>v[i];
int uu,vv;
for(int i=;i<=m;i++){
cin>>uu>>vv;
a[uu][vv]=a[vv][uu]=;
}
int ans=0x3f3f3f3f;
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
for(int k=;k<=n;k++){
if(i==j||j==k||k==i) continue;
if(a[i][j]==a[j][k]&&a[j][k]==a[k][i]&&a[k][i]==){ ans=min(ans,v[i]+v[j]+v[k]);
}
}
}
}
if(ans==0x3f3f3f3f) cout<<-;
else
cout<<ans<<endl;
}
B
暴力
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 13000005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,int>pli;
typedef pair<char,int> pci;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long MOD=1e9+;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
string str;
cin>>str;
int ans=;
while(str.length()!=){
int tmp=;
for(int i=;i<str.length();i++) tmp+=str[i]-'';
ans++;
str=to_string(tmp);
}
cout<<ans<<endl;
}
C
贪心
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 13000005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,int>pli;
typedef pair<int,char> pic;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long MOD=1e9+;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int book[]; int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
string str;
int n;
cin>>str>>n;
for(int i=;i<str.length();i++){
book[str[i]-'a']++;
}
if(str.length()<=n) cout<<<<endl<<endl;
else{
set<char>se;
vector<pic>ve;
for(int i=;i<;i++){
ve.pb({book[i],'a'+i});
}
sort(ve.begin(),ve.end());
for(int i=;i<ve.size();i++){
if(ve[i].first<=n){
n-=ve[i].first;
se.insert(ve[i].second);
}
else{
break;
}
}
string s="";
for(int i=;i<str.length();i++){
if(se.count(str[i])) continue;
else s+=str[i];
}
set<char>ss;
for(int i=;i<s.length();i++){
ss.insert(s[i]);
}
cout<<ss.size()<<endl<<s<<endl;
}
}
D
树状数组+离散化
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 13000005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,int>pli;
typedef pair<int,char> pic;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long MOD=1e9+;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int n,m; map<int,int>tree; int lowbit(int x){
return x&(-x);
} void add(int x,int v){
while(x<=n+){
tree[x]=(tree[x]+v)%MOD;
x+=lowbit(x);
}
} int getsum(int x){
int ans=;
while(x){
ans=(ans+tree[x])%MOD;
x-=lowbit(x);
}
return ans;
}
vector<pii>ve; int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
cin>>n>>m;
int a,b;
for(int i=;i<=m;i++){
cin>>a>>b;
ve.pb({b+,a+});
}
sort(ve.begin(),ve.end());
add(,);
for(int i=;i<m;i++){
int s=ve[i].second,t=ve[i].first;
int tmp=getsum(t-)-getsum(s-);
tmp=(tmp%MOD+MOD)%MOD;
add(t,tmp);
}
int ans=getsum(n+)-getsum(n);
cout<<(ans%MOD+MOD)%MOD<<endl;
}