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

  1. 水题 Codeforces Beta Round #70 (Div. 2) A. Haiku

    题目传送门 /* 水题:三个字符串判断每个是否有相应的元音字母,YES/NO 下午网速巨慢:( */ #include <cstdio> #include <cstring> ...

  2. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  3. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  4. Codeforces Beta Round #79 (Div. 2 Only)

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

  5. Codeforces Beta Round #77 (Div. 2 Only)

    Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...

  6. Codeforces Beta Round #76 (Div. 2 Only)

    Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...

  7. Codeforces Beta Round #75 (Div. 2 Only)

    Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...

  8. Codeforces Beta Round #74 (Div. 2 Only)

    Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...

  9. Codeforces Beta Round #73 (Div. 2 Only)

    Codeforces Beta Round #73 (Div. 2 Only) http://codeforces.com/contest/88 A 模拟 #include<bits/stdc+ ...

随机推荐

  1. day41-解决粘包问题

    一.socket缓冲区 研究粘包之前先看看socket缓冲区的问题: 二.socket缓存区的详细解释 每个socket被创建后,都会分配两个缓冲区,输入缓冲区和输出缓冲区. write()/send ...

  2. 现学现卖——Keil uVision 使用教程

    Keil uVision 使用教程 1.如果有旧的工程在,先关闭旧工程.Project -> Close Project2.新建工程.Project -> New uVision Proj ...

  3. UI5-学习篇-12-Eclipse同步ABAP服务器UI5应用

    如何在ABAP服务器上部署和运行SAPUI5应用程序 https://blogs.sap.com/2013/06/15/how-to-deploy-and-run-sapui5-application ...

  4. U3D GPU蒙皮

    在U3D中默认情况下是使用CPU蒙皮的,在BUILDING SETTING中的others中可以设置为GPU skinning

  5. 将文本文件中的\n字符串变成换行符

    1.用notepad打开文件 2.查看换行符,不同操作系统的换行符是不同的. [视图]——[显示符号]——[显示行尾符]. 我的操作系统是windows,所以行尾符是CR LF——对应的正则表达式是\ ...

  6. PRC远程过程调用

    RPC(Remote Promote Call) 一种进程间通信方式.允许像调用本地服务一样调用远程服务. RPC框架的主要目标就是让远程服务调用更简单.透明.RPC框架负责屏蔽底层的传输方式(TCP ...

  7. Think you can pronounce these 10 words correctly? You might be

    Think you can pronounce these 10 words correctly?  You might be surprised! Share Tweet Share Tagged ...

  8. eclipse中配置Tomcat服务器以及新建项目

    eclipse配置Tomcat服务器 http://jingyan.baidu.com/article/ca2d939dd90183eb6d31ce79.html eclipse中配置Tomcat服务 ...

  9. 28.注解2.md

    目录 1. 特点 2.优点 3. 源注解-部分 4.自定义注解 5.使用注解获 1. 特点 注释:给程序员阅读使用 注解:给编译器阅读使用 2.优点 简化配置文件 灵活方便 3. 源注解-部分 //修 ...

  10. 基于docker的wekan部署

    镜像地址: https://hub.docker.com/r/wekanteam/wekan/ wiki: https://github.com/wekan/wekan/wiki#Developmen ...