题解Codeforces Round #597 (Div. 2)

A:送分,裸的gcd。

 1 #include<stdio.h>
 2 #define il inline
 3 #define it register int
 4 int T,a,b,d;
 5 il void  gcd(int a,int b){
 6     if(!b){d=a;return;}
 7     gcd(b,a%b);
 8 }
 9 il void fr(int &num){
10     num=0;char c=getchar();int p=1;
11     while(c<‘0‘||c>‘9‘) c==‘-‘?p=-1,c=getchar():c=getchar();
12     while(c>=‘0‘&&c<=‘9‘) num=num*10+c-‘0‘,c=getchar();
13     num*=p;
14 }
15 int main(){
16     fr(T);
17     while(T--)
18         fr(a),fr(b),gcd(a,b),d==1?puts("Finite"):puts("Infinite");
19     return 0;
20 }

B:送分,直接把能用的都用掉就行。

 1 #include<stdio.h>
 2 #include<string.h>
 3 #define it register int
 4 #define il inline
 5 using namespace std;
 6 const int N=100005;
 7 int T,n,a,b,c,ans;
 8 char s[N],o[N];
 9 il void fr(int &num){
10     num=0;char c=getchar();int p=1;
11     while(c<‘0‘||c>‘9‘) c==‘-‘?p=-1,c=getchar():c=getchar();
12     while(c>=‘0‘&&c<=‘9‘) num=num*10+c-‘0‘,c=getchar();
13     num*=p;
14 }
15 int main(){
16     fr(T);
17     while(T--){
18         scanf("%d%d%d%d%s",&n,&a,&b,&c,s+1),ans=n;
19         for(it i=1;i<=n;++i){
20             if(s[i]==‘S‘&&a) --a,o[i]=‘R‘;
21             else if(s[i]==‘R‘&&b) --b,o[i]=‘P‘;
22             else if(s[i]==‘P‘&&c) --c,o[i]=‘S‘;
23             else o[i]=‘K‘;
24         }
25         for(it i=1;i<=n;++i)
26             if(o[i]==‘K‘){
27                 if(a) o[i]=‘R‘,--a;
28                 else if(b) o[i]=‘P‘,--b;
29                 else if(c) o[i]=‘S‘,--c;
30                 --ans;
31             }
32         if(ans<((n+1)>>1)) puts("NO");
33         else{
34             puts("YES");
35             for(it i=1;i<=n;++i) putchar(o[i]);putchar(‘\n‘);
36         }
37     }
38     return 0;
39 }

C:送分,手玩一下发现每个块的贡献是斐波那契数列。而且好像这题之前CF出过的。

 1 #include<stdio.h>
 2 #include<string.h>
 3 #define it register int
 4 #define il inline
 5 using namespace std;
 6 const int N=1000005;
 7 const long long mod=1e9+7;
 8 char s[N];
 9 long long f[N],ans=1;
10 int n;
11 il void fr(int &num){
12     num=0;char c=getchar();int p=1;
13     while(c<‘0‘||c>‘9‘) c==‘-‘?p=-1,c=getchar():c=getchar();
14     while(c>=‘0‘&&c<=‘9‘) num=num*10+c-‘0‘,c=getchar();
15     num*=p;
16 }
17 int main(){
18     scanf("%s",s+1),n=strlen(s+1);
19     f[0]=f[1]=1,f[2]=2;for(it i=3;i<=n;++i) f[i]=(f[i-1]+f[i-2])%mod;
20     for(it i=1;i<=n;++i){
21         if(s[i]==‘u‘||s[i]==‘n‘){
22             it j;
23             for(j=i;s[j]==s[i]&&j<=n;++j);
24             ans=1ll*ans*f[j-i]%mod,i=j-1;
25         }
26         if(s[i]==‘m‘||s[i]==‘w‘){
27             putchar(‘0‘);return 0;
28         }
29     }
30     printf("%lld",ans);
31     return 0;
32 }

D:最小生成树,预处理每一对(i,j)的连边就行。n个点连通就跳出不做。而且这题据说是USACO某道原题。。

E:不会。

F:数位dp。我不会告诉你我离正解只差一个特判的!

我还是菜啊,怎么大家纷纷切E,我就E不会怎么搞。。

而且。。用血的教训告诉大家:

1.数位dp,要判断l=0的情况,不可以盲减一。

2.交题目的时候手速要快,不要犹豫!否则你就是交不上去的那个人……

由于还在system testing 先放上我没有fst的几题的代码。

原文地址:https://www.cnblogs.com/Kylin-xy/p/11780408.html

时间: 2024-11-07 17:34:37

题解Codeforces Round #597 (Div. 2)的相关文章

Codeforces Round #597 (Div. 2) A. Good ol&#39; Numbers Coloring

链接: https://codeforces.com/contest/1245/problem/A 题意: Consider the set of all nonnegative integers: 0,1,2,-. Given two integers a and b (1≤a,b≤104). We paint all the numbers in increasing number first we paint 0, then we paint 1, then 2 and so on. Ea

题解Codeforces Round #595 (Div. 3)(CF1249)

开题1小时(雾)严重影响我的提交以及做题心情..我刚开题就发现有人阿克了.. 实际上这场div3真心简单良心很休闲. A:送分题,先排序,每次枚举一下这个数可以加到哪个集合里,加进去就行. 1 #include<stdio.h> 2 #include<algorithm> 3 #define it register int 4 #define il inline 5 using namespace std; 6 const int N=1000005; 7 int a[N],o[N

Codeforces Round #597 (Div. 2) E. Hyakugoku and Ladders 概率dp

E. Hyakugoku and Ladders Hyakugoku has just retired from being the resident deity of the South Black Snail Temple in order to pursue her dream of becoming a cartoonist. She spent six months in that temple just playing "Cat's Cradle" so now she w

Codeforces Round #597 (Div. 2) B. Restricted RPS

链接: https://codeforces.com/contest/1245/problem/B 题意: Let n be a positive integer. Let a,b,c be nonnegative integers such that a+b+c=n. Alice and Bob are gonna play rock-paper-scissors n times. Alice knows the sequences of hands that Bob will play. H

题解——Codeforces Round #508 (Div. 2) T2 (构造)

按照题意构造集合即可 注意无解情况的判断 #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> #include <vector> #include <map> using namespace std; int n,sum; int main(){ scanf("%d",&n); if(n==1){ printf

题解——Codeforces Round #508 (Div. 2) T1 (模拟)

依照题意暴力模拟即可A掉 #include <cstdio> #include <algorithm> #include <cstring> #include <set> using namespace std; char s[100100]; int n,k,barrel[30]; int main(){ scanf("%d %d",&n,&k); scanf("%s",s+1); for(int i

题解——Codeforces Round #508 (Div. 2) T3 (贪心)

贪心的选取最优解 然后相减好 记得要开long long #include <cstdio> #include <algorithm> #include <cstring> #include <set> #include <queue> #define int long long using namespace std; int ansa=0,ansb=0,posa=1,posb=1,n,a[1000100],b[1000100]; bool c

Codeforces Round #597 (Div. 2) D. Shichikuji and Power Grid

题意: 二维平面上n个点,每个点可以建厂,也可以与其他点连边,建厂花费为\(c_i\),与j连边花费为\((k_i+k_j)*dis(i,j)\),dis为两点之间的欧式距离,求让每个点都通电的最小花费与方案 思路: 维护使这个点通电的花费的优先队列,一开始先把建厂放进去,然后每次拿出最小花费的点i,再用i去更新与i建路的花费(有点像最小生成树). #include<bits/stdc++.h> #define ll long long #define pii pair<int,int&

codeforces Codeforces Round #597 (Div. 2) D. Shichikuji and Power Grid

#include<bits/stdc++.h> using namespace std ; int n; struct City { int id; long long x,y; //坐标 long long cc,kk; //自建的花费,连线的花费 bool self;//是否建站 int fa;//连线的站 bool operator < (const City & a)const { return cc<a.cc; } } c[2005]; int main() {