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. jquery (内置遍历数组的函数,事件)

    内置遍历数组的函数: 1. $.map(array, function() { }); 取到数组或者对象array中每一项进行遍历  然后在function中处理: var attr = [1,2,3 ...

  2. ES6中export default与export的区别

    1.export default 和export都可以用于导出常量,函数,文件,模块等: 2.可以在模块中通过import+(常量 | 函数 | 文件 | 模块)名的方式,将其导入,以便能够对其进行使 ...

  3. MYSQL-JDBC批量新增-更新-删除

    目录 1 概述 2 开启MYSQL服务端日志 3 深入MYSQL/JDBC批量插入 3.1 从一个例子出发 3.2 JDBC的批量插入操作 3.3 两个常被忽略的问题 3.5 误区 4 MYSQL/J ...

  4. getX,getY,getScrollX,getScrollY,ScrollTo(),ScrollBy()辨析

    前言:前两天看了自定义控件,其中有一些东西我觉得有必要深入理解一下 以下图为例: getX(),getY()返回的是触摸点A相对于view的位置 getRaw(),getRawY()返回的是触摸点B相 ...

  5. windows cmd 生成文件目录树

    一.背景 之前逛GitHub的时候看到有大佬在描述项目结构的时候使用了一种文件目录树的格式 │ └─student_information_management_system │ │ ├─build ...

  6. Mbp,一个用于学习.net core的开发框架

    Mbp(https://github.com/mbpframework/Mbp)是一个.net core 3的企业级web开发框架,是我个人用于学习.net core而发起的一个开源项目.这个借鉴了国 ...

  7. dotnetcore执行shell脚本

    我们可以使有dotnetcore跨平台的特性,优雅的实现在dotnetcore执行shell (bash).  代码如下: using System; using System.Collections ...

  8. Android Activity启动流程, app启动流程,APK打包流程, APK安装过程

    1.Activity启动流程 (7.0版本之前) 从startActivity()开始,最终都会调用startActivityForResult() 在该方法里面会调用Instrumentation. ...

  9. 使用 Redis 进行阅读数统计并定时持久化

    之前,统计每篇博文的阅读数的方式是经过筛选去重之后直接更新数据库,并发压力直接传导到数据库,假设1秒有1000个并发请求,传统方案会在1秒内并发进行1000次数据库更新操作. 为了降低数据库的并发压力 ...

  10. 使用StampedLock

    /** * StampedLock和ReadWriteLock相比,改进之处在于:读的过程中也允许获取写锁后写入!这样一来,我们读的数据就可能不一致,所以,需要一点额外的代码来判断读的过程中是否有写入 ...