Codeforces Round #607 (Div. 1)
A. Cut and Paste
题解
在计算答案的时候,我们发现只需要知道这个字符串前\(l\) 个具体是啥就行了。所以对于每一组询问,我们暴力把这个字符串前\(l\) 的位都算出来,然后剩下的就推就行了。
(我之前是对于每一次复制前都会暴力复制一份复制内容,但是发现会被全是1的情况卡爆,因为如果是1的话就不用复制)
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<string>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long LL;
typedef pair<int,int> PII;
inline int read()
{
int x=0,f=1;char c=getchar();
while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
while(isdigit(c)){x=x*10+c-'0';c=getchar();}
return x*f;
}
const int MOD=1000000007;
int T,x;
char s[3000010],tmp[3000010];
int main()
{
T=read();
while(T--)
{
x=read();
scanf("%s",s);
int len=strlen(s);
int i=1;
while(len<=x && i<=x)
{
int tmp=len;
for(int j=1;j<s[i-1]-'0';j++)
for(int k=i;k<tmp;k++)s[len++]=s[k];
i++;
}
if(i==x+1){printf("%d\n",len%MOD);continue;}
int ans=len;
while(i<=x)ans=(ans+((ans-i)*(s[i-1]-'0'-1)%MOD+MOD)%MOD)%MOD,i++;
printf("%d\n",ans);
}
return 0;
}
B. Beingawesomeism
题解
无聊至极的分类讨论题,代码写的特别丑
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<queue>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long LL;
typedef pair<int,int> PII;
inline int read()
{
int x=0,f=1;char c=getchar();
while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
while(isdigit(c)){x=x*10+c-'0';c=getchar();}
return x*f;
}
int T;
int n,m;
char pic[100][100];
bool check1()
{
bool ok1=0;
for(int i=0;i<n;i++)if(pic[i][0]=='P')ok1=1;
if(!ok1)return 1;
bool ok2=0;
for(int i=0;i<n;i++)if(pic[i][m-1]=='P')ok2=1;
if(!ok2)return 1;
bool ok3=0;
for(int i=0;i<m;i++)if(pic[0][i]=='P')ok3=1;//printf("ok:%d\n",ok1);
if(!ok3)return 1;
bool ok4=0;
for(int i=0;i<m;i++)if(pic[n-1][i]=='P')ok4=1;// printf("ok:%d\n",ok1);
if(!ok4)return 1;
return 0;
}
bool check2()
{
if(pic[0][0]=='A')return 1;
if(pic[0][m-1]=='A')return 1;
if(pic[n-1][0]=='A')return 1;
if(pic[n-1][m-1]=='A')return 1;
for(int i=1;i<n-1;i++)
{
bool ok=0;
for(int j=0;j<m;j++)
if(pic[i][j]=='P')ok=1;
if(!ok)return 1;
}
for(int i=1;i<m-1;i++)
{
bool ok=0;
for(int j=0;j<n;j++)
if(pic[j][i]=='P')ok=1;
if(!ok)return 1;
}
return 0;
}
bool check3()
{
bool ok1=0;
for(int i=1;i<m-1;i++)if(pic[0][i]=='A')ok1=1;
if(ok1)return 1;
bool ok2=0;
for(int i=1;i<m-1;i++)if(pic[n-1][i]=='A')ok2=1;
if(ok2)return 1;
bool ok3=0;
for(int i=1;i<n-1;i++)if(pic[i][0]=='A')ok3=1;
if(ok3)return 1;
bool ok4=0;
for(int i=1;i<n-1;i++)if(pic[i][m-1]=='A')ok4=1;
if(ok4)return 1;
return 0;
}
int main()
{
T=read();
while(T--)
{
n=read();m=read();
for(int i=0;i<n;i++)scanf("%s",pic[i]);
bool flag=0,flag2=0;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
{
if(pic[i][j]=='A')flag=1;
if(pic[i][j]=='P')flag2=1;
}
if(!flag)printf("MORTAL\n");
else if(!flag2)printf("0\n");
else if(check1())printf("1\n");
else if(check2())printf("2\n");
else if(check3())printf("3\n");
else printf("4\n");
}
return 0;
}
C. Jeremy Bearimy
题解
这种点对的题,之前做过类似的题,就是依次考虑每一条边。
先说最小值,考虑一条边是否被选中的话只需要看一下这个儿子的大小,如果这个儿子的size是偶数的话,那么在下面就已经能完成匹配,没有必要连上来了,否则这条边就会被用上。
再说最大值,对于这条边肯定是被多个点对覆盖的,我们要算这条边对于最终答案贡献了几次,那么就是$min \lbrace size[v],n-size[v] \rbrace $
代码是队友写的,极为短小精悍。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
int read()
{
int k=0,f=1;char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=getchar()) k=k*10+c-'0';return k*f;
}
const int N=400055;
int T,n,m,tot,to[N],nextt[N],head[N],w[N],size[N];
ll ans1,ans2;
void add(int a,int b,int c)
{
to[++tot]=b;
nextt[tot]=head[a];
head[a]=tot;
w[tot]=c;
}
void dfs1(int u,int f)
{
size[u]=1;
for(int i=head[u];i;i=nextt[i])
if(to[i]!=f)
{
dfs1(to[i],u);size[u]+=size[to[i]];
if(size[to[i]]&1) ans1+=w[i];
ans2+=1ll*min(size[to[i]],n-size[to[i]])*w[i];
}
}
int main()
{
T=read();
while(T--)
{
int a,b,c;
ans1=ans2=tot=0;
n=read()*2;
for(int i=1;i<n;i++)
{
a=read();b=read();c=read();
add(a,b,c);add(b,a,c);
}
dfs1(1,0);
printf("%lld %lld\n",ans1,ans2);
for(int i=1;i<=n;i++)
head[i]=0;
}
return 0;
}
Codeforces Round #607 (Div. 1)的更多相关文章
- Codeforces Round #607 (Div. 1) Solution
从这里开始 比赛目录 我又不太会 div 1 A? 我菜爆了... Problem A Cut and Paste 暴力模拟一下. Code #include <bits/stdc++.h> ...
- 【cf补题记录】Codeforces Round #607 (Div. 2)
比赛传送门 这里推荐一位dalao的博客-- https://www.cnblogs.com/KisekiPurin2019/ A:字符串 B:贪心 A // https://codeforces.c ...
- Codeforces Round #607 (Div. 2) 题解
Suffix Three Azamon Web Services Cut and Paste Beingawesomeism Jeremy Bearimy Miss Punyverse Suffix ...
- Codeforces Round #607 (Div. 2)
A - Suffix Three 题意:规定三种语言的结尾符,给出字符串,判断是什么语言. void test_case() { string s; cin >> s; reverse(s ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
随机推荐
- [权限管理系统(四)]-spring boot +spring security短信认证+redis整合
[权限管理系统]spring boot +spring security短信认证+redis整合 现在主流的登录方式主要有 3 种:账号密码登录.短信验证码登录和第三方授权登录,前面一节Sprin ...
- Web基础了解版01-html-css
HTML 网页构成 摘要 说明 结构(HTML) HTML是网页内容的载体.内容就是网页制作者放在页面上想要让用户浏览的信息,可以包含文字.图片.视频等. 表现(CSS) CSS样式是表现.就像网页的 ...
- 【GTK编程】安装与测试
版权声明:本文为博主原创文章,转载请注明出处. https://www.cnblogs.com/YaoYing/ 前言 领导让做个类似平板触摸的GUI程序,通过触摸两块区域,实现背景图片的左右切换.本 ...
- 学习构建调试Linux内核网络代码的环境MenuOS系统
构建调试Linux内核网络代码的环境MenuOS系统 一.前言 这是网络程序设计的第三次实验,主要是学习自己编译linux内核,构建一个具有简易功能的操作系统,同时在系统上面进行调试linux内核网络 ...
- Centos7 Openresty 开发环境
首先要安装编译环境 yum group install "Development Tools" yum install pcre-devel openssl-devel gcc c ...
- 在Atmel Studio7中创建ASF项目
使用ASF自带例程的方式创建程序是很方便,但是因为系统例程支持的ATMEL开发板往往和用户板配置不同,所以我们需要自己创建项目.下面介绍在AS7.0中快速创建一个ASF项目的方法. 1.首先从菜单开始 ...
- 清晰架构(Clean Architecture)的Go微服务: 程序结构
我使用Go和gRPC创建了一个微服务,并试图找出最佳的程序结构,它可以用作我未来程序的模板. 我有Java背景,并发现自己在Java和Go之间挣扎,它们之间的编程理念完全不同.我写了一系列关于在项目工 ...
- Elasticsearch7.5.0源码编译
环境及工具 JDK12 Gradle5.6.2 GIT 源码及预处理 到github将代码clone下来,可以根据自己的需求来获取版本,例如 git checkout v7.5.0 提前下载gradl ...
- Unity-使用UnityRemote调试手机Android Studio打印日志
抛出问题: 1.Unity调试Android的时候默认情况是build打包成apk,安装到手机运行,调试起来很不方便,如何快速在手机上运行呢? 2.如何像unity的console一样在andro ...
- JMeter多脚本间的启动延时
JMeter做压测时,当需要多个jmx脚本依次执行时,需要用到“启动延时”,即间隔可设置的时间后启动运行下一个jmx脚本. 实现“启动延时”的方法有2个. 方法一.利用JMeter线程组中的" ...