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 ...
随机推荐
- Linux常见指令大全
转载自https://www.cnblogs.com/caozy/p/9261224.html 前言 本文特点 授之以渔:了解命令学习方法.用途:不再死记硬背,拒绝漫无目的: 准确无误:所有命令执行通 ...
- Spring Cloud Alibaba 新一代微服务解决方案
本篇是「跟我学 Spring Cloud Alibaba」系列的第一篇, 每期文章会在公众号「架构进化论」进行首发更新,欢迎关注. 1.Spring Cloud Alibaba 是什么 Spring ...
- 如何在Android手机上进行自动化测试(下)
版权声明:允许转载,但转载必须保留原链接:请勿用作商业或者非法用途 前言 通过阅读本篇教程,你将会了解到: 如何使用Poco对Android原生应用进行测试 Poco支持直接对任何Android原生应 ...
- GHOST CMS - Package.json
Package.json The package.json file is a set of meta data about a theme. package.json 文件是一组关于主题的元数据. ...
- Elasticsearch 语法指南(全)
所有的语句默认都是没有用户名和密码,如果你的 es 集群做了安全认证的话,请在每一个 crul 后面加上 -u username:password 例如: curl -u admin:123456 - ...
- C# 派生和继承(派生类与基类)
using System; using System.Collections.Generic; using System.Text; namespace 继承 { class Program { st ...
- Android WebView 加载富文本内容
WebView加载数据的方式有两种: 1. webView.loadUrl(data);//加载url 2. webView.loadDataWithBaseURL(null,data, " ...
- 部署flas到服务器:No module named flask
首先,你要先把nginx和uwsgi安装好(个人觉得这搭起来比较舒服),可以通过pip 或者源安装,具体方法在前面我有提到过,好了接下来我就讲讲我的踩坑经历与解决办法. 我先采用的pip insta ...
- PHP使用递归按层级查找数据
今天主要介绍一下使用递归来按层级查找数据.原理挺简单的,主要是通过父级id一级一级的循环查找子级,使用PHP循环代码也很容易实现,不过如果层级越多,PHP重复代码也越多,这时可以使用递归来实现这功能. ...
- 利用WPF生成Q币充值二维码——扫码登录篇
一.前言 虽然腾讯官方不支持使用二维码充值Q币,但对于喜欢钻研的人来说这不是问题,本文利用WPF技术讲解从扫码登录到生成Q币充值二维码的一整套解决方案. 因为充值Q币需要先用QQ号登录官网.所以我们首 ...