Codeforces Round #459 (Div. 2)

人生第一次CF炸裂掉了13的rating,只写了两道签到题,真的菜

T1:

输出一个长度为n的字符串,对于第i位,如果i是斐波那契数,输出O 否则输出o

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cstdlib>
 5 #include<cmath>
 6 #include<algorithm>
 7 #include<queue>
 8 #include<vector>
 9 #include<map>
10 #define inf 2139062143
11 #define ll long long
12 #define MAXN
13 #define MOD
14 using namespace std;
15 inline int read()
16 {
17     int x=0,f=1;char ch=getchar();
18     while(!isdigit(ch)) {if(ch=='-') f=-1;ch=getchar();}
19     while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
20     return x*f;
21 }
22 int n,a=1,b=1,c;
23 bool hsh[1001];
24 int main()
25 {
26     n=read();
27     hsh[1]=1;
28     while(c<=n) c=a+b,a=b,b=c,hsh[c]=1;
29     for(int i=1;i<=n;i++)
30         if(hsh[i])cout<<'O';
31         else cout<<'o';
32 }
View Code

T2:

一个map就搞定的事

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cstdlib>
 5 #include<cmath>
 6 #include<algorithm>
 7 #include<queue>
 8 #include<vector>
 9 #include<map>
10 #define inf 2139062143
11 #define ll long long
12 #define MAXN 1010
13 #define MOD
14 using namespace std;
15 inline int read()
16 {
17     int x=0,f=1;char ch=getchar();
18     while(!isdigit(ch)) {if(ch=='-') f=-1;ch=getchar();}
19     while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
20     return x*f;
21 }
22 int n,m;
23 char str[MAXN][15];
24 map <string,int> mp;
25 int main()
26 {
27     char ch[30],k[30];
28     string s;s+=';';
29     n=read(),m=read();
30     for(int i=1;i<=n;i++)
31     {
32         scanf("%s %s",str[i],ch);
33         mp[ch+s]=i;
34     }
35     for(int i=1;i<=m;i++)
36     {
37         scanf("%s %s",ch,k);
38         printf("%s %s #%s
",ch,k,str[mp[k]]);
39     }
40 }
View Code

T3:

考试的时候石乐志

对于一个串求有几个子串是pretty的

一个串是pretty时它的括号是匹配的(?可以转化为左括号或右括号)

思路:

就是根据一个性质来判断每个子串是否pretty

对于一个串s 它pretty

当且仅当 它有偶数位,对于任意两个字符之间的一个位置 位置左侧的"("数量+"?"数量>=")"数量 位置右侧的 ")"数量+"?"数量>="("数量

然后预处理出这两个数组就行了

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<cstdlib>
 5 #include<cstring>
 6 #include<algorithm>
 7 #include<vector>
 8 #include<queue>
 9 #define inf 2139062143
10 #define ll long long
11 #define MAXN 5010
12 using namespace std;
13 inline int read()
14 {
15     int x=0,f=1;char ch=getchar();
16     while(!isdigit(ch)) {if(ch=='-') f=-1;ch=getchar();}
17     while(isdigit(ch)) {x=x*10+ch-'0';ch=getchar();}
18     return x*f;
19 }
20 bool l[MAXN][MAXN],r[MAXN][MAXN],f;
21 int n,tmp;
22 char ch[MAXN];
23 int main()
24 {
25     scanf("%s",ch+1);n=strlen(ch+1);
26     for(int i=1;i<=n;i++)
27     {
28         f=tmp=0;
29         for(int j=i;j<=n;j++) 
30         {
31             if(ch[j]==')') tmp--;
32             else tmp++;
33             if(tmp<0) f=1;
34             l[i][j]=f;
35         }
36     }
37     for(int i=1;i<=n;i++)
38     {
39         f=tmp=0;
40         for(int j=i;j>=1;j--) 
41         {
42             if(ch[j]=='(') tmp--;
43             else tmp++;
44             if(tmp<0) f=1;
45             r[j][i]=f;
46         }
47     }
48     int ans=0;
49     for(int i=1;i<=n;i++)
50         for(int j=i+1;j<=n;j+=2)
51             if(!l[i][j]&&!r[i][j]) ans++;
52     printf("%d",ans);
53 }
View Code

T4:

两个人在DAG上玩游戏,每个人可以沿着边上走,每条边上有一个字母

每个人只能走的边上的字母必须大于等于上一个人走的边的字母

求两个人起点所有情况的胜负情况

思路:

设(bool) dp u v k 表示一个人在u 另一个人在v 上一条边是k的胜负值

则若u走到i节点,而dp v i edge(u->i)为0 则dp u v k为1

然后在图上转移

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<cstdlib>
 5 #include<cstring>
 6 #include<algorithm>
 7 #include<vector>
 8 #include<queue>
 9 #define inf 2139062143
10 #define ll long long
11 #define MAXN 105
12 using namespace std;
13 inline int read()
14 {
15     int x=0,f=1;char ch=getchar();
16     while(!isdigit(ch)) {if(ch=='-') f=-1;ch=getchar();}
17     while(isdigit(ch)) {x=x*10+ch-'0';ch=getchar();}
18     return x*f;
19 }
20 int ans[MAXN][MAXN][30];
21 int mp[MAXN][MAXN],n,m;
22 int dp(int u,int v,int val)
23 {
24     //cout<<u<<" "<<v<<" "<<val<<endl;
25     if(ans[u][v][val]) return ans[u][v][val];
26     for(int i=1;i<=n;i++)
27     {
28         if(val>mp[u][i]) continue;
29         if(dp(v,i,mp[u][i])==2) return ans[u][v][val]=1;
30     }
31     return ans[u][v][val]=2;
32 }
33 int main()
34 {
35     n=read(),m=read();int a,b;char ch[3];
36     memset(mp,0xff,sizeof(mp));
37     for(int i=1;i<=m;i++) 
38     {
39         a=read(),b=read();
40         scanf("%s",ch);
41         mp[a][b]=ch[0]-'a';
42     }
43     for(int i=1;i<=n;i++)
44     {
45         for(int j=1;j<=n;j++)
46             if(dp(i,j,0)==1) cout<<"A";
47             else cout<<"B";
48         cout<<endl;
49     }
50 }
View Code
原文地址:https://www.cnblogs.com/yyc-jack-0920/p/8383468.html