http://codeforces.com/problemset/problem/478/C 讨厌的贪心... 思路其实挺简单的,就是尽量2 1这么放气球就行 但是各种细节比较恶心 可能有更好的解法? 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using namespace std;
int ans=0;
int u=0;
int p[4]={};
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
cin>>p[1]>>p[2]>>p[3];
sort(p+1,p+4,cmp);
u=p[3];
p[1]-=u;
p[2]-=u;
p[3]-=u;
int q;
q=min(p[1]-p[2],p[2]);
ans+=q;
p[1]-=q*2;
p[2]-=q;
sort(p+1,p+3,cmp);
if(p[1]==p[2]&&p[2]!=0)
{
q=p[1]/3;
ans+=q*2;
p[1]-=q*3;
p[2]-=q*3;
}
if(p[1]==2&&p[2]==2)
{
ans++;
}
if(p[1]!=0)
{
ans+=min(u,p[1]/3);
}
ans+=u;
cout<<ans;
return 0;
}
http://codeforces.com/problemset/problem/268/C 最开始想了一段时间... 后来发现直接各种取对角线就行了... 没有对角线的就找到最大的正方形取个对角线... 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using namespace std;
int n,m;
int main()
{
cin>>n>>m;
int s,t;
if(n<m)
{
s=0;
t=m-n;
cout<<n+1<<endl;
while(s<=n)
{
cout<<s<<" "<<t<<endl;
s++;
t++;
}
return 0;
}
if(n>m)
{
s=n-m;
t=0;
cout<<m+1<<endl;
while(s<=n)
{
cout<<s<<" "<<t<<endl;
s++;
t++;
}
return 0;
}
if(n==m)
{
s=0;
t=n;
cout<<n+1<<endl;
while(s<=n&&t>=0)
{
cout<<s<<" "<<t<<endl;
s++;
t--;
}
return 0;
}
return 0;
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using namespace std;
long long n,k,d;
long long p[110]={};
long long q[110]={};
long long ans;
int main()
{
cin>>n>>k>>d;
p[0]=1;
q[0]=1;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=k;j++)
{
if(i-j>=0)
{
p[i]+=p[i-j];
p[i]%=mod;
}
}
for(int j=1;j<d;j++)
{
if(i-j>=0)
{
q[i]+=q[i-j];
q[i]%=mod;
}
}
}
ans=p[n]-q[n];
while(ans<0) ans+=mod;
cout<<ans;
return 0;
}
http://codeforces.com/problemset/problem/441/C 模拟即可 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using namespace std;
int n,m,k;
int u;
int p;
int nu;
bool vis[301][301]={};
int x,y;
int main()
{
cin>>n>>m>>k;
u=n*m/k;
x=1; y=1;
p=1;
nu=1;
for(int i=1;i<=n;i++)
{
vis[i][0]=1;
vis[i][m+1]=1;
}
cout<<u<<" ";
while(x<=n)
{
cout<<x<<" "<<y<<" ";
vis[x][y]=1;
if(vis[x][y+1]==0)
{
y++;
}
else if(vis[x][y-1]==0)
{
y--;
}
else if(vis[x+1][y]==0)
{
x++;
}
p++;
if(p==u+1)
{
if(nu==k) break;
nu++;
p=1;
if(nu==k)
{
u+=n*m-u*k;
}
cout<<endl;
cout<<u<<" ";
}
}
return 0;
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using namespace std;
int n,p;
char c[100010]={};
bool ne[100010]={};
int u[100010]={};
int an=0;
int l,r;
int ll,rr,ml,mr;
int ans=100000;
int main()
{
cin>>n>>p;
ll=100000;
rr=0;
ml=0;
mr=100000;
for(int i=1;i<=n;i++)
{
cin>>c[i];
}
for(int i=1;i<=n;i++)
{
if(c[i]!=c[n-i+1])
{
ne[i]=1;
ne[n-i+1]=1;
an+=min(26-abs((int)c[n-i+1]-(int)c[i]),abs((int)c[n-i+1]-(int)c[i]));
if(i<=n/2)
{
ml=max(ml,i);
}
if(i>=n/2+1)
{
mr=min(mr,i);
}
ll=min(ll,i);
rr=max(rr,i);
}
}
an/=2;
if(an==0)
{
cout<<0;
return 0;
}
int t;
t=ml-ll;
int u;
u=abs(p-ll);
ans=min(u+t,ans);
u=abs(p-ml);
ans=min(u+t,ans);
u=abs(p-mr);
ans=min(u+t,ans);
u=abs(p-rr);
ans=min(u+t,ans);
cout<<ans+an;
return 0;
}