Codeforces Round #288 (Div. 2)

A. Pasha and Pixels

题目大意:给出n*m的棋盘,初始为全白,每次在上面使一个格子变黑,问多少次的时候使得棋盘上出现2×2的黑格

思路:模拟

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 #include<queue>
 5 #define maxn 900000
 6 #define LL long long
 7 using namespace std;
 8 bool map[1001][1001];
 9 int main()
10 {
11         int n,m,k,ans=0,x,y;
12         scanf("%d%d%d",&n,&m,&k);
13         for(int i=1;i<=k;i++)
14         {
15                 scanf("%d%d",&x,&y);
16                 map[x][y]=1;
17                 if(map[x-1][y]&&map[x-1][y-1]&&map[x][y-1]){ans=i;break;}
18                 if(map[x+1][y]&&map[x+1][y+1]&&map[x][y+1]){ans=i;break;}
19                 if(map[x-1][y]&&map[x-1][y+1]&&map[x][y+1]){ans=i;break;}
20                 if(map[x+1][y]&&map[x+1][y-1]&&map[x][y-1]){ans=i;break;}
21         }
22         printf("%d",ans);
23         return 0;
24 }

B. Anton and currency you all know

题目大意:给你一个奇数,让你交换数中两个数码,使得它变为偶数,并且形成的新数字最大,问能形成最大的数为多少,不行输出-1

思路:还是模拟,由于给的是奇数,只要找到最高位比最后一位小的偶数交换一下,其他情况乱搞一下

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 #include<queue>
 5 #include<map>
 6 #include<vector>
 7 #include<algorithm>
 8 #define maxn 900000
 9 #define LL long long
10 using namespace std;
11 char ch[maxn];
12 int main()
13 {
14         scanf("%s",ch+1);
15         int len=strlen(ch+1),j=-1,flag=0;
16         for(int i=1;i<len;i++)if(!((ch[i]-‘0‘)&1))
17         {
18                 j=i;
19                 if(ch[i]<ch[len]){swap(ch[i],ch[len]);flag=1;break;}
20         }
21         if(j==-1){printf("-1\n");return 0;}
22         if(flag==0)swap(ch[j],ch[len]);
23         for(int i=1;i<=len;i++)
24         {
25                 printf("%c",ch[i]);
26         }
27         return 0;
28 }

C. Anya and Ghosts

题目大意:简单来说就是有m个点,每个时间点最多向右延伸一条线段,每条线段长为t,每个点要被r条线段覆盖,问最少加几条线段?

思路:暴力吧。。。

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 #include<queue>
 5 #include<algorithm>
 6 #define maxn 900000
 7 #define LL long long
 8 #define T 401
 9 using namespace std;
10 int w[maxn],candle[maxn];
11 int main()
12 {
13         int m,t,r,ans=0;
14         scanf("%d%d%d",&m,&t,&r);
15         if(t<r)
16         {
17                 printf("-1\n");
18                 return 0;
19         }
20         for(int i=1;i<=m;i++)
21         {
22                 scanf("%d",&w[i]);
23                 int last=0;
24                 for(int j=w[i]-t;j<=w[i]-1;j++)
25                 {
26                         if(candle[j+T])last++;
27                 }
28                 for(int j=w[i]-r+last;j<=w[i]-1;j++)
29                 {
30                         candle[j+T]=1;
31                         ans++;
32                 }
33         }
34         printf("%d\n",ans);
35         return 0;
36 }

D. Tanya and Password

题目大意:n个三个字符的字符串,两个字符串可以拼起来当且仅当一个字符串的后两个字符等于另一个字符的前两个字符,然后就可以插在一起,问n个字符串能否插成n+2个字符的串

思路:把每两个字母看成点,然后跑欧拉路经

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 #include<queue>
 5 #include<map>
 6 #include<vector>
 7 #include<algorithm>
 8 #define maxn 900000
 9 #define LL long long
10 using namespace std;
11 vector<vector<int> >G(maxn);
12 string str[maxn];
13 char ch[maxn];
14 int head[maxn],next[maxn],point[maxn],now;
15 int degree[maxn],ans[maxn],hh,selfc[maxn];
16 int mp[maxn];
17 bool visit[maxn];
18 void add(int x,int y)
19 {
20         G[x].push_back(y);
21         next[++now]=head[x];
22         head[x]=now;
23         point[now]=y;
24 }
25 int mhash(string s)
26 {
27         return s[0]*130+s[1];
28 }
29 void dfs(int s)
30 {
31         while(!G[s].empty())
32         {
33                 //cout<<str[point[i]];
34                 int v=G[s].back();
35                 G[s].pop_back();
36                 dfs(v);
37                 ans[++hh]=v;
38         }
39         for(int i=1;i<=selfc[s];i++)ans[++hh]=s;
40         selfc[s]=0;
41 }
42 int main()
43 {
44         int n,h=0,st;
45         scanf("%d",&n);
46         for(int i=1;i<=n;i++)
47         {
48                 string ss="",t="";
49                 scanf("%s",ch+1);
50                 ss=ss+ch[1]+ch[2];t=t+ch[2]+ch[3];
51                 int u=st=mp[mhash(ss)],v=mp[mhash(t)];
52                 if(u==0){u=mp[mhash(ss)]=++h;str[h]=ss;}
53                 if(v==0 && ss!=t){v=mp[mhash(t)]=++h;str[h]=t;}
54                 else if(ss==t)v=u;
55                 degree[u]++;degree[v]--;
56                 if(u==v)
57                 {
58                         selfc[u]++;
59                 }else add(u,v);
60         }
61         int d=0,t=0,s=0;
62         for(int i=1;i<=h;i++)
63         {
64                 if(degree[i]!=0)
65                 {
66                         if(degree[i]==1 && s==0){s=i;}
67                         else if(degree[i]==-1 && t==0){t=i;}
68                         else {printf("NO\n");return 0;}
69                 }
70         }
71         if(t==0)s=st;
72         //cout<<s<<endl;
73         //for(int i=head[1];i;i=next[i]) printf("%d\n",point[i]);
74         if(d<=2)
75         {
76                 dfs(s);
77                 if(hh!=n)
78                 {
79                         printf("NO\n");
80                         return 0;
81                 }
82                 printf("YES\n");
83                 cout<<str[s][0]<<str[s][1];
84                 for(int i=hh;i>=1;i--)
85                 {
86                         cout<<str[ans[i]][1];
87                 }
88         }
89         else printf("NO\n");
90         return 0;
91 }

时间: 2024-08-02 09:52:22

Codeforces Round #288 (Div. 2)的相关文章

Codeforces Round #288 (Div. 2) 待续

A. Pasha and Pixels ( 暴力 ) 题意:给一个n*m的矩阵染色(初始为全白),如果在k步之内染出一个2*2的矩阵,输出最小步数,否则输出0 分析:brute force #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std; int M[ 1010 ][ 1010 ]; int step, r, c, k

Codeforces Round #288 (Div. 2)B(字符串)

题意:交换两个数,使得交换后的数是偶数且尽可能大: KEY:分情况,1末尾数为偶数,即找到比它小的偶数交换,假如没有比它小的偶数,不用交换.2末尾数是奇数,再分情况,<1>全都是奇数(这个可以在一开始就判断掉),即输出-1,<2>有一个偶数,无论如何谁大谁小都要交换,<3>全部偶数都比奇数大,从n - 2(n是字符串长度)开始找到一个偶数交换即可,<4>如果有一些偶数比末尾数大,有些比它小,即从0开始找到比奇数小的那个偶数交换即可.其实是分类讨论.(有更好的

Codeforces Round #288 (Div. 2) ABCDE

A题 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 #include <cmath> 6 #include <vector> 7 #include <map> 8 #include <queue> 9 10 using namespace std; 11 12 #define LL

Codeforces Round #288 (Div. 2) A,B,C,D,E

A:一个一个点向图里面加,判断其所在的位置与其他的点是否可以构成小矩形就可以了. B:贪心,如果前面的偶数有比他小的就找到一个最靠前的交换,如果前面的偶数都比它小,就找一个最靠后的交换. C:贪心,把蜡烛尽可能的放在恶魔,来之前,这样可以充分利用蜡烛的时间,模拟一下,不停地向前方就可以了.如果蜡烛时间小于需要的数目,一定不可以. const int maxn = 2010; int vis[maxn]; int num[maxn]; int main() { int m, t, r; while

Codeforces Round #288 (Div. 2) A. Pasha and Pixels

A. Pasha and Pixels time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Pasha loves his phone and also putting his hair up... But the hair is now irrelevant. Pasha has installed a new game to

Codeforces Round #288 (Div. 2) B. Anton and currency you all know

B. Anton and currency you all know time limit per test 0.5 seconds memory limit per test 256 megabytes input standard input output standard output Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that

Codeforces Round #288 (Div. 2) C. Anya and Ghosts

C. Anya and Ghosts time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lo

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i