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)的更多相关文章

  1. Codeforces Round #607 (Div. 1) Solution

    从这里开始 比赛目录 我又不太会 div 1 A? 我菜爆了... Problem A Cut and Paste 暴力模拟一下. Code #include <bits/stdc++.h> ...

  2. 【cf补题记录】Codeforces Round #607 (Div. 2)

    比赛传送门 这里推荐一位dalao的博客-- https://www.cnblogs.com/KisekiPurin2019/ A:字符串 B:贪心 A // https://codeforces.c ...

  3. Codeforces Round #607 (Div. 2) 题解

    Suffix Three Azamon Web Services Cut and Paste Beingawesomeism Jeremy Bearimy Miss Punyverse Suffix ...

  4. Codeforces Round #607 (Div. 2)

    A - Suffix Three 题意:规定三种语言的结尾符,给出字符串,判断是什么语言. void test_case() { string s; cin >> s; reverse(s ...

  5. 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 ...

  6. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  7. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  8. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  9. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

随机推荐

  1. 【Canvas】311- 解决 canvas 在高清屏中绘制模糊的问题

    点击上方"前端自习课"关注,学习起来~ 一.问题分析 使用 canvas 绘制图片或者是文字在 Retina 屏中会非常模糊.如图: 因为 canvas 不是矢量图,而是像图片一样 ...

  2. centos7 php(mariadb)安装pdo

    环境:centos7+php5.4.16+mariadb5.5.52 在centos7环境下安装PDO,安装的时候都是自己分开安装的,先装的PHP(httpd)后装的mariadb. 数据库安装完成后 ...

  3. HyperLedger Fabric 1.4 生产环境动态添加组织及节点

    网易云课堂视频在线教学,地址:https://study.163.com/course/introduction/1209401942.htm 1.1 操作概述      在“kafka生产环境部署” ...

  4. Python之利用Whoosh搭建轻量级搜索

      本文将简单介绍Python中的一个轻量级搜索工具Whoosh,并给出相应的使用示例代码. Whoosh简介   Whoosh由Matt Chaput创建,它一开始是一个为Houdini 3D动画软 ...

  5. Nuxt+Vuex初体验

    小呀嘛小二郎,背着书包上学堂... 今天一个困扰了我一周时间的问题终于被我解决了,值得庆祝 在Nuxt中使用Vuex实现数据存储 首先: 在store目录下新建一个index.js文件 需要有两个组件 ...

  6. Cocos Creator 资源加载流程剖析【三】——Load部分

    Load流程是整个资源加载管线的最后一棒,由Loader这个pipe负责(loader.js).通过Download流程拿到内容之后,需要对内容做一些"加载"处理.使得这些内容可以 ...

  7. laravel身份验证-Auth的使用

    laravel自带了auth类和User模型来帮助我们很方便的实现用户登陆.判断.首先,先配置一下相关参数 app/config/auth.php: model 指定模型table 指定用户表这里我只 ...

  8. webpack 打包less文件配置

    1 npm install less less-loader -D 2匹配规则

  9. weed3-2.2.细讲插入和更新

    Weed3 一个微型ORM框架(只有0.1Mb哦) 源码:https://github.com/noear/weed3 源码:https://gitee.com/noear/weed3 这篇重点讲讲插 ...

  10. 理解MVVM在react、vue中的使用

    理解MVVM在react.vue中的使用 一:什么是MVC.为什么不用MVC 1:MVC的含义: M(modal):是应用程序中处理数据逻辑的部分. V (view)  :是应用程序中数据显示的部分. ...