Codeforces Beta Round #70 (Div. 2)
Codeforces Beta Round #70 (Div. 2)
http://codeforces.com/contest/78
A
- #include<bits/stdc++.h>
- using namespace std;
- #define lson l,mid,rt<<1
- #define rson mid+1,r,rt<<1|1
- #define sqr(x) ((x)*(x))
- #define pb push_back
- #define eb emplace_back
- #define maxn 1000006
- #define eps 1e-8
- #define pi acos(-1.0)
- #define rep(k,i,j) for(int k=i;k<j;k++)
- typedef long long ll;
- typedef unsigned long long ull;
- map<char,int>mp;
- int main(){
- #ifndef ONLINE_JUDGE
- // freopen("input.txt","r",stdin);
- #endif
- std::ios::sync_with_stdio(false);
- mp['a']=,mp['e']=,mp['i']=,mp['o']=,mp['u']=;
- string str;
- getline(cin,str);
- int num=;
- for(int i=;i<str.length();i++){
- num+=mp[str[i]];
- }
- if(num==){
- getline(cin,str);
- num=;
- for(int i=;i<str.length();i++){
- num+=mp[str[i]];
- }
- if(num==){
- getline(cin,str);
- num=;
- for(int i=;i<str.length();i++){
- num+=mp[str[i]];
- }
- if(num==) {
- cout<<"YES"<<endl;
- return ;
- }
- }
- }
- cout<<"NO"<<endl;
- }
B
找规律
- #include<bits/stdc++.h>
- using namespace std;
- #define lson l,mid,rt<<1
- #define rson mid+1,r,rt<<1|1
- #define sqr(x) ((x)*(x))
- #define pb push_back
- #define eb emplace_back
- #define maxn 1000006
- #define eps 1e-8
- #define pi acos(-1.0)
- #define rep(k,i,j) for(int k=i;k<j;k++)
- typedef long long ll;
- typedef unsigned long long ull;
- map<char,int>mp;
- int main(){
- #ifndef ONLINE_JUDGE
- // freopen("input.txt","r",stdin);
- #endif
- std::ios::sync_with_stdio(false);
- int n;
- cin>>n;
- cout<<"ROYGBIV";
- n-=;
- for(int i=;i<n;i++){
- if(i%==){
- cout<<"G";
- }
- else if(i%==){
- cout<<"B";
- }
- else if(i%==){
- cout<<"I";
- }
- else {
- cout<<"V";
- }
- }
- }
C
博弈 如果n是偶数的话,后手必胜,因为他可以模仿先手,如果n是奇数的话,判断先手能否完成切割任务
- #include<bits/stdc++.h>
- using namespace std;
- #define lson l,mid,rt<<1
- #define rson mid+1,r,rt<<1|1
- #define sqr(x) ((x)*(x))
- #define pb push_back
- #define eb emplace_back
- #define maxn 1000006
- #define eps 1e-8
- #define pi acos(-1.0)
- #define rep(k,i,j) for(int k=i;k<j;k++)
- typedef long long ll;
- typedef unsigned long long ull;
- map<char,int>mp;
- int n,m,k;
- bool panduan(){
- int sq=sqrt(m);
- for(int i=;i<=sq;i++){
- if(m%i==){
- if(i>=k&&m/i>) return ;
- else if(i>&&m/i>=k) return ;
- }
- }
- return ;
- }
- int main(){
- #ifndef ONLINE_JUDGE
- // freopen("input.txt","r",stdin);
- #endif
- std::ios::sync_with_stdio(false);
- cin>>n>>m>>k;
- if(n%==) cout<<"Marsel";
- else {
- if(panduan()){
- cout<<"Timur";
- }
- else{
- cout<<"Marsel";
- }
- }
- }
D
- #include<bits/stdc++.h>
- using namespace std;
- #define lson l,mid,rt<<1
- #define rson mid+1,r,rt<<1|1
- #define sqr(x) ((x)*(x))
- #define pb push_back
- #define eb emplace_back
- #define maxn 1000006
- #define eps 1e-8
- #define pi acos(-1.0)
- #define rep(k,i,j) for(int k=i;k<j;k++)
- typedef long long ll;
- typedef unsigned long long ull;
- map<char,int>mp;
- int n,m,k;
- int main(){
- #ifndef ONLINE_JUDGE
- // freopen("input.txt","r",stdin);
- #endif
- std::ios::sync_with_stdio(false);
- ll n;
- cin>>n;
- ll ans=;
- for(double i=8.0/;i<*n/sqrt();i+=){
- double tmp=(sqrt(16.0*n*n/-*i*i)-i)/2.0-2.0/;
- if(tmp>) ans+=(ll)tmp/+;
- }
- cout<<ans*+<<endl;
- }
E
最大流。先标记毒气到达每个实验室的时间,再判断科学家能否在毒气或规定时间内到达救生仓,然后建图
- #include<bits/stdc++.h>
- using namespace std;
- #define lson l,mid,rt<<1
- #define rson mid+1,r,rt<<1|1
- #define sqr(x) ((x)*(x))
- #define pb push_back
- #define eb emplace_back
- #define maxn 1000006
- #define eps 1e-8
- #define pi acos(-1.0)
- #define rep(k,i,j) for(int k=i;k<j;k++)
- typedef long long ll;
- typedef unsigned long long ull;
- #define MAXN 200005
- const int N=;
- const int M=;
- const int INF=0x3f3f3f3f;
- using namespace std;
- int n;
- struct Edge{
- int v,next;
- int cap,flow;
- }edge[MAXN*];//注意这里要开的够大。。不然WA在这里真的想骂人。。问题是还不报RE。。
- int cur[MAXN],pre[MAXN],gap[MAXN],path[MAXN],dep[MAXN];
- int cnt=;//实际存储总边数
- void isap_init()
- {
- cnt=;
- memset(pre,-,sizeof(pre));
- }
- void isap_add(int u,int v,int w)//加边
- {
- edge[cnt].v=v;
- edge[cnt].cap=w;
- edge[cnt].flow=;
- edge[cnt].next=pre[u];
- pre[u]=cnt++;
- }
- void add(int u,int v,int w){
- isap_add(u,v,w);
- isap_add(v,u,);
- }
- bool bfs(int s,int t)//其实这个bfs可以融合到下面的迭代里,但是好像是时间要长
- {
- memset(dep,-,sizeof(dep));
- memset(gap,,sizeof(gap));
- gap[]=;
- dep[t]=;
- queue<int>q;
- while(!q.empty()) q.pop();
- q.push(t);//从汇点开始反向建层次图
- while(!q.empty())
- {
- int u=q.front();
- q.pop();
- for(int i=pre[u];i!=-;i=edge[i].next)
- {
- int v=edge[i].v;
- if(dep[v]==-&&edge[i^].cap>edge[i^].flow)//注意是从汇点反向bfs,但应该判断正向弧的余量
- {
- dep[v]=dep[u]+;
- gap[dep[v]]++;
- q.push(v);
- // if(v==sp)//感觉这两句优化加了一般没错,但是有的题可能会错,所以还是注释出来,到时候视情况而定
- // break;
- }
- }
- }
- return dep[s]!=-;
- }
- int isap(int s,int t)
- {
- if(!bfs(s,t)) return ;
- memcpy(cur,pre,sizeof(pre));
- //for(int i=1;i<=n;i++)
- //cout<<"cur "<<cur[i]<<endl;
- int u=s;
- path[u]=-;
- int ans=;
- while(dep[s]<n)//迭代寻找增广路,n为节点数
- {
- if(u==t)
- {
- int f=INF;
- for(int i=path[u];i!=-;i=path[edge[i^].v])//修改找到的增广路
- f=min(f,edge[i].cap-edge[i].flow);
- for(int i=path[u];i!=-;i=path[edge[i^].v])
- {
- edge[i].flow+=f;
- edge[i^].flow-=f;
- }
- ans+=f;
- u=s;
- continue;
- }
- bool flag=false;
- int v;
- for(int i=cur[u];i!=-;i=edge[i].next)
- {
- v=edge[i].v;
- if(dep[v]+==dep[u]&&edge[i].cap-edge[i].flow)
- {
- cur[u]=path[v]=i;//当前弧优化
- flag=true;
- break;
- }
- }
- if(flag)
- {
- u=v;
- continue;
- }
- int x=n;
- if(!(--gap[dep[u]]))return ans;//gap优化
- for(int i=pre[u];i!=-;i=edge[i].next)
- {
- if(edge[i].cap-edge[i].flow&&dep[edge[i].v]<x)
- {
- x=dep[edge[i].v];
- cur[u]=i;//常数优化
- }
- }
- dep[u]=x+;
- gap[dep[u]]++;
- if(u!=s)//当前点没有增广路则后退一个点
- u=edge[path[u]^].v;
- }
- return ans;
- }
- int t;
- string people[],cap[];
- int book[][];
- struct sair{
- int x,y,step;
- };
- int dir[][]={,,,,,-,-,};
- void bfs1(int x,int y){
- sair s,e;
- s.step=,s.x=x,s.y=y;
- memset(book,-,sizeof(book));
- queue<sair>Q;
- Q.push(s);
- book[s.x][s.y]=;
- while(!Q.empty()){
- s=Q.front();
- Q.pop();
- if(s.step>=t) break;
- for(int i=;i<;i++){
- e.x=s.x+dir[i][];
- e.y=s.y+dir[i][];
- if(e.x>=&&e.x<n&&e.y>=&&e.y<n&&book[e.x][e.y]==-&&people[e.x][e.y]!='Y'){
- e.step=s.step+;
- book[e.x][e.y]=e.step;
- Q.push(e);
- }
- }
- }
- }
- void bfs2(int x,int y){
- sair s,e;
- int tmp[][];
- memset(tmp,-,sizeof(tmp));
- s.x=x,s.y=y,s.step=;
- tmp[s.x][s.y]=;
- queue<sair>Q;
- Q.push(s);
- int w=people[x][y]-'';
- add(s.x*n+s.y,s.x*n+s.y+n*n,w);
- while(!Q.empty()){
- s=Q.front();
- Q.pop();
- if(s.step>=t) break;
- for(int i=;i<;i++){
- e.x=s.x+dir[i][];
- e.y=s.y+dir[i][];
- if(e.x<||e.x>=n||e.y<||e.y>=n||people[e.x][e.y]=='Z'||people[e.x][e.y]=='Y') continue;
- if(tmp[e.x][e.y]==-&&(book[e.x][e.y]==-||book[e.x][e.y]>=s.step+)){
- if(book[e.x][e.y]==s.step+){
- if(cap[e.x][e.y]>=''&&cap[e.x][e.y]<=''){
- add(x*n+y,e.x*n+e.y+n*n,w);
- }
- }
- else{
- e.step=s.step+;
- tmp[e.x][e.y]=e.step;
- add(x*n+y,e.x*n+e.y+n*n,w);
- Q.push(e);
- }
- }
- }
- }
- }
- int main(){
- #ifndef ONLINE_JUDGE
- // freopen("input.txt","r",stdin);
- #endif
- std::ios::sync_with_stdio(false);
- cin>>n>>t;
- int sx,sy;
- isap_init();
- for(int i=;i<n;i++){
- cin>>people[i];
- for(int j=;j<n;j++){
- if(people[i][j]=='Z'){
- sx=i,sy=j;
- }
- }
- }
- for(int i=;i<n;i++) cin>>cap[i];
- bfs1(sx,sy);
- for(int i=;i<n;i++){
- for(int j=;j<n;j++){
- if(people[i][j]>=''&&people[i][j]<=''){
- bfs2(i,j);
- }
- }
- }
- int S=n*n*;
- int T=n*n*+;
- for(int i=;i<n;i++){
- for(int j=;j<n;j++){
- if(people[i][j]>=''&&people[i][j]<=''){
- add(S,i*n+j,people[i][j]-'');
- }
- if(cap[i][j]>=''&&cap[i][j]<=''){
- add(i*n+j+n*n,T,cap[i][j]-'');
- }
- }
- }
- n=n*n*+;
- int ans=isap(S,T);
- cout<<ans<<endl;
- }
Codeforces Beta Round #70 (Div. 2)的更多相关文章
- 水题 Codeforces Beta Round #70 (Div. 2) A. Haiku
题目传送门 /* 水题:三个字符串判断每个是否有相应的元音字母,YES/NO 下午网速巨慢:( */ #include <cstdio> #include <cstring> ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
- Codeforces Beta Round #77 (Div. 2 Only)
Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...
- Codeforces Beta Round #76 (Div. 2 Only)
Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...
- Codeforces Beta Round #75 (Div. 2 Only)
Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...
- Codeforces Beta Round #74 (Div. 2 Only)
Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...
- Codeforces Beta Round #73 (Div. 2 Only)
Codeforces Beta Round #73 (Div. 2 Only) http://codeforces.com/contest/88 A 模拟 #include<bits/stdc+ ...
随机推荐
- WPF 透明窗体
窗体属性中设置:Background="Transparent" AllowsTransparency="True" WindowStyle="Non ...
- Java 基础 - 对象池
对象池 优点: 防止过多的创建对象合理利用对象, 缺点: 会有线程阻塞 Demo 测试代码 package com.cjcx.pay.obj; import java.util.Enumerati ...
- java-部分精选面试题
JVM的类加载机制是什么?有哪些实现方式? 类加载机制: 类的加载指的是将类的.class文件中的二进制数据读入到内存中,将其放在运行时数据区的方法去内,然后在堆区创建一个java.lang.Clas ...
- Python3.7中urllib.urlopen 报错问题
import urllib web = urllib.urlopen('https://www.baidu.com') f = web.read() print(f) 报错: Traceback (m ...
- B树、B-树、B+树、B*树的定义和区分
MySQL是基于B+树聚集索引组织表 B树 即二叉搜索树: 1.所有非叶子结点至多拥有两个儿子(Left和Right): 2.所有结点存储一个关键字: 3.非叶子结点的左指针指向小于其关键字的子树,右 ...
- Shell条件表达式
Shell编程中经常需要判断文件状态.字符串是否相等以及两个数值大小等情况,基于这些比较结果再做执行相关操作.本文主要讲述文件状态.字符串.数值大小的判断比较方法. 文件状态判断 文件状态的判断通常使 ...
- C++多态,虚函数,虚函数表,纯虚函数
1.多态性 指相同对象收到不同消息或不同对象收到相同消息时产生不同的实现动作. C++支持两种多态性:编译时多态性,运行时多态性. a.编译时多态性:通过重载函数实现 ,模板(2次编译) ...
- 使用__all__限制模块可被导入对象
经常我们会编写自定义模块,用于被别的脚本调用;有时候为了方便,会使用from module_name import *的方式导入,这样会把模块中全部对象导入进来; 使用__all__结合列表,可以控制 ...
- python opencv3 给图片加中文
转自:https://www.cnblogs.com/arkenstone/p/6961453.html opencv3.2将中文输出到图片上 opencv自带的putText函数无法输出utf8类型 ...
- requests库的文档--快速上手
快速上手 迫不及待了吗?本页内容为如何入门 Requests 提供了很好的指引.其假设你已经安装了 Requests.如果还没有,去安装一节看看吧. 首先,确认一下: Requests 已安装 Req ...