0%

Codeforces Div 2 C 天梯 16——20

http://codeforces.com/problemset/problem/382/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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include<bits/stdc++.h>
using namespace std;
int n;
int a[100010]={};
bool cmp(int a,int b)
{
return a<b;
}
int ans=0;
int c[100010]={};
int num=0;
map<int,int> ha;
int d;
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
sort(a+1,a+n+1,cmp);
if(n==1)
{
cout<<-1;
return 0;
}
if(n==2)
{
if(a[2]==a[1])
{
cout<<1<<endl<<a[2];
return 0;
}
int d=a[2]-a[1];
if(d%2==0)
{
cout<<3<<endl;
cout<<a[1]-d<<" "<<a[1]+d/2<<" "<<a[2]+d<<endl;
return 0;
}
}
bool bj=0;
for(int i=2;i<=n;i++)
{
d=a[i]-a[i-1];
if(d!=0) bj=1;
if(ha[d]==0)
{
num++;
c[num]=d;
}
ha[d]++;
}
if(bj==0)
{
cout<<1<<endl;
cout<<a[1];
return 0;
}
if(num>=3)
{
cout<<0;
return 0;
}
if(num==2)
{
if(c[2]<c[1])
{
swap(c[1],c[2]);
}
if(c[2]==c[1]*2&&ha[c[2]]==1)
{
cout<<1<<endl;
for(int i=2;i<=n;i++)
{
d=a[i]-a[i-1];
if(d==c[2])
{
cout<<a[i-1]+c[1]<<endl;
return 0;
}
}
}
else
{
cout<<0;
return 0;
}
}
if(num==1)
{
cout<<2<<endl;
cout<<a[1]-c[1]<<" "<<a[n]+c[1]<<endl;
return 0;
}
return 0;
}
http://codeforces.com/problemset/problem/388/A 正难则反的思想... 我们发现这个题,正着贪心似乎很难贪,但是如果从小到大排序之后倒着贪心,就很好做啦
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
#include<bits/stdc++.h>
using namespace std;
int n;
int x[110]={};
bool cmp(int x,int y)
{
return x<y;
}
int h[110]={};
int num;
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>x[i];
}
sort(x+1,x+n+1,cmp);
num=0;
for(int i=1;i<=n;i++)
{
bool bj=0;
for(int j=1;j<=num;j++)
{
if(h[j]<=x[i])
{
bj=1;
h[j]++;
break;
}
}
if(bj==0)
{
num++;
h[num]=1;
}
}
cout<<num;
return 0;
}
http://codeforces.com/problemset/problem/9/C 枚举一下,然后用map判重
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
#include<bits/stdc++.h>
using namespace std;
int ans=0;
int n;
int u=0;
map<int,bool> ha;
void ff(int x)
{
if(u>=1&&u<=n)
{
if(ha[u]==0)
{
ans++;
ha[u]=1;
}
}
if(x==11) return;
int p=u;
u=u*10;
ff(x+1);
u=p;
u=u*10+1;
ff(x+1);
u=p;
return;
}
int main()
{
cin>>n;
ff(1);
cout<<ans;
return 0;
}
http://codeforces.com/problemset/problem/339/C 我觉得是挺难的一道题... d[i][j][k] i代表进行了多少步 j代表两个托盘之间的差(-10到10,我程序里用0到20表示的) k代表之前用的物品的质量 状态表示完了,状态转移的很好办了
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include<bits/stdc++.h>
using namespace std;
bool d[1010][21][11]={};
string s;
int n;
int ans[1010]={};
int num;
int main()
{
cin>>s>>n;
for(int i=1;i<=10;i++) d[0][10][i]=1;
for(int i=1;i<=n;i++)
{
for(int j=0;j<=20;j++)
{
for(int k=1;k<=10;k++)
{
if(d[i-1][j][k]==1)
{
for(int p=1;p<=10;p++)
{
if(s[p-1]=='1'&&p!=k)
{
if(i%2==1)
{
int a=j+p;
if(a>10)
{
d[i][a][p]=1;
}
}
else
{
int a=j-p;
if(a<10)
{
d[i][a][p]=1;
}
}
}
}
}
}
}
}
for(int i=0;i<=20;i++)
{
for(int j=1;j<=10;j++)
{
if(d[n][i][j]==1)
{
cout<<"YES"<<endl;
num=0;
int pr=n;
int t=j;
int u=i;
while(1)
{
num++;
ans[num]=t;
if(pr%2==1)
{
u-=t;
}
else u+=t;
pr--;
if(pr==0) break;
for(int k=1;k<=10;k++)
{
if(k!=t)
{
if(d[pr][u][k]==1)
{
t=k;
break;
}
}
}
}
for(int k=num;k>=1;k--)
{
cout<<ans[k]<<" ";
}
return 0;
}
}
}
cout<<"NO"<<endl;
return 0;
}
http://codeforces.com/problemset/problem/350/C 就是贪心,因为每个炸弹拆完之后都要回到终点,所以就是走一个矩形边 在这之前要对点进行排序 我这里是先对x的绝对值排序,再对y的绝对值排序 不过我现在打字的时候突然想到,对曼哈顿距离排序似乎应该也是可以的...
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
61
62
63
64
65
66
67
68
#include<bits/stdc++.h>
using namespace std;
struct pp
{
int x,y;
} p[100010];
int n;
int ans=0;
bool cmp(pp a,pp b)
{
if(abs(a.x)!=abs(b.x))
{
return abs(a.x)<abs(b.x);
}
return abs(a.y)<abs(b.y);
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d%d",&p[i].x,&p[i].y);
if(p[i].x==0||p[i].y==0)
{
ans+=4;
}
else ans+=6;
}
sort(p+1,p+n+1,cmp);
printf("%d\n",ans);
for(int i=1;i<=n;i++)
{
if(p[i].x>0)
{
printf("1 %d R\n",p[i].x);
}
if(p[i].x<0)
{
printf("1 %d L\n",-p[i].x);
}
if(p[i].y>0)
{
printf("1 %d U\n",p[i].y);
}
if(p[i].y<0)
{
printf("1 %d D\n",-p[i].y);
}
printf("2\n");
if(p[i].x>0)
{
printf("1 %d L\n",p[i].x);
}
if(p[i].x<0)
{
printf("1 %d R\n",-p[i].x);
}
if(p[i].y>0)
{
printf("1 %d D\n",p[i].y);
}
if(p[i].y<0)
{
printf("1 %d U\n",-p[i].y);
}
printf("3\n");
}
}