CCPC-Wannafly Summer Camp 2019 Day1
比赛链接:https://vjudge.net/contest/314412#overview
A - One-dimensional Japanese Crossword CodeForces - 721A
题目链接:http://codeforces.com/problemset/problem/721/A
题目大意:长度为n的串,B是黑色,W是白色,问这个串中有几个黑色的连通块,并输出每个的长度
思路:签到水题,直接暴力判过去
代码:
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define ll long long
const ll mod=1000000007;
char s[105];
int a[105];
int main()
{
int n;
scanf("%d",&n);
scanf("%s",s);
int cnt=0;
for(int i=0;i<n;i++)
{
if(s[i]=='B')
{
int ans=0;
while(1)
{
if(s[i]=='B') ans++,i++;
else break;
}
a[++cnt]=ans;
}
}
printf("%d\n",cnt);
if(cnt) printf("%d",a[1]);
for(int i=2;i<=cnt;i++)
printf(" %d",a[i]);
printf("\n");
return 0;
}
B - Passwords CodeForces - 721B
题目链接:http://codeforces.com/problemset/problem/721/B
题目大意:有n个密码串不知道哪个是正确的,现在从里面随机选试(先选短的,短的都选完了再选长的),问最快和最慢分别需要多久才能试对,输错k次要等待5秒,告诉你正确的密码串
思路:长度相同是随机选,所以最快就是在试完所有比正确密码串短的后第一个就选到正确的,最慢是在这个长度中最后选到。
按这个思路暴拟
代码:
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define ll long long
const ll mod=1000000007;
char s[105];
int a[105];
int main()
{
int n,k;
scanf("%d%d",&n,&k);
for(int i=0;i<n;i++)
{
scanf("%s",s);
int len=strlen(s);
a[len]++;
}
scanf("%s",s);
int l=strlen(s),ans1=0,ans2=0;
for(int i=1;i<l;i++)
ans1+=a[i];
ans2=ans1+a[l]-1;
ans2=ans2+(ans2/k)*5;
ans1=ans1+(ans1/k)*5;
printf("%d %d\n",ans1+1,ans2+1);
return 0;
}
C - Journey CodeForces - 721C (补)
题解:https://blog.csdn.net/chimchim04/article/details/98345500
D - Maxim and Array CodeForces - 721D (补)
这道题比赛想到思路,但是不知道怎么维护最小绝对值
题解:https://blog.csdn.net/chimchim04/article/details/98313416
E - Jamie and Alarm Snooze CodeForces - 916A
题目链接:http://codeforces.com/problemset/problem/916/A
题目大意:要在hh:mm的时候起床,现在要定一个闹钟,闹钟的时间要包含数字7,并且距离起床的时间要最短且是x的倍数,输出这个最小倍数
思路:暴拟水题,虽然我的代码很丑,但是要补的题太多了我就不再做一遍了
代码:
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define ll long long
const ll mod=1000000007;
int main()
{
int n,h,m;
scanf("%d%d%d",&n,&h,&m);
int x=h%10,y=m%10;
if(x==7||y==7) printf("0\n");
else
{
int ans=0;
if(y>7) ans=y-7,m=(m/10)*10+7;
else if(y<7)
{
if(m/10>0) ans=y+3,m=(m/10-1)*10+7;
else
{
if(h==0) h=23;
else h=h-1;
if(h%10==7) ans=y+1,m=59;
else ans=y+3,m=57;
}
}
while(1)
{
if(ans%n==0) break;
int flag=0;
if(h%10==7)
{
if((ans%n)+59>=n)
{
ans=(ans/n)*n+n;
flag=1;
}
else
{
ans=ans+59+3;
h=h-1;
m=57;
}
if(ans%n==0) flag=1;
}
if(flag) break;
for(int i=1;i<=(m/10)+1;i++)
{
ans+=10;
if(ans%n==0)
{
flag=0;
break;
}
}
if(flag) break;
m=57;
h=h-1;
if(h==-1) h=23;
if(h%10==7)
{
m=59;
ans-=2;
}
}
int cnt=ans/n;
printf("%d\n",cnt);
}
return 0;
}
F - Jamie and Binary Sequence (changed after round) CodeForces - 916B (补)
贪心模拟题,但是比赛的时候还没来得及看这道题
题解:https://blog.csdn.net/chimchim04/article/details/98479027
G - Jamie and Interesting Graph CodeForces - 916C
题目链接:http://codeforces.com/problemset/problem/916/C
题目大意:让你构建一个n个节点m条边的图,满足:1. 节点1到n的最短路是素数, 2.最小生成树的边权和为素数
思路:直接设一条边 1到n 权值为2,使满足条件1, 然后把 2 到 n-1 的点都与 节点1 连一条边,设权值为1,现在以及构成最小生成树,如果边权和不是素数,就把n-1点与1相连的边的权修改成能满足的值 。现在的图已经满足条件1,2,且有n-1条边,剩余的边就按顺序连从2开始和别的点相连,知道有m条边,权值设为最小生成树的权值和,这样就不会影响前面的两条件
代码:
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define ll long long
const ll mod=1000000007;
const int N=200015;
int n,m,cnt;
int a[N],p[N];
void init()
{
cnt=0;
p[1]=p[0]=1;
for(int i=2;i<=200005;i++)
if(!p[i])
{
a[cnt++]=i;
for(int j=i+i;j<=N;j+=i)
p[j]=1;
}
}
int x[N],y[N],w[N];
int main()
{
init();
scanf("%d%d",&n,&m);
int tot=0,ans=0,k;
x[++tot]=1,y[tot]=n,w[tot]=2;
ans+=w[tot];
for(int i=2;i<n;i++)
{
x[++tot]=1;
y[tot]=i;
w[tot]=1;
ans+=w[tot];
}
if(p[ans]!=0)
{
k=lower_bound(a,a+cnt,ans)-a;
w[tot]=a[k]-ans+1;
ans=a[k];
}
for(int i=2;i<=n;i++)
{
for(int j=i+1;j<=n;j++)
{
if(tot==m) break;
x[++tot]=i;
y[tot]=j;
w[tot]=ans;
}
if(tot==m) break;
}
printf("2 %d\n",ans);
for(int i=1;i<=tot;i++)
printf("%d %d %d\n",x[i],y[i],w[i]);
return 0;
}
H - 树上染色 (补)
题解:https://blog.csdn.net/chimchim04/article/details/98338571
I - Rikka with Match HDU - 6091 (待补)
J - Karen and Neighborhood CodeForces - 815E (待补)
K - Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths
CodeForces - 741D (待补)
树上启发式和并