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+ ...
随机推荐
- oracle PL/SQL的介绍
转自:http://blog.sina.com.cn/s/blog_4c302f060101i4o1.html 一 PL/SQL的介绍 1 PL/SQL是什么? PL/SQL(procedural l ...
- 清除linux服务器缓存 clean.sh
#!/bin/sh#根据输入参数创建后台进程的日志名称#FileName: createNohupPhpForbak.sh #export JAVA_HOME=/root/lib/jdk1.7.0_7 ...
- 获取数据库表中自增长最新的id
mybatis <insert id="InsertCourse"> insert into training_course(type_id,course_title, ...
- APP-6-百度地图导航
1.代码部分 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <me ...
- Activity生命周期,切换,参数传递,bundle(包),值对象,Activity参数返回,Activity的启动模式
Activity代表手机屏幕的一屏,或是平板电脑中的一个窗口.它是android应用中最重要的组成单元之一,提供了和用户交互的可视化界面.在一个Activity中,可以添加很多组件,这些组件负责具体的 ...
- Linux:写一个简单的服务器
开始了新篇章:Linux网络编程. 基础知识: 套接字概念 Socket本身有"插座"的意思,在Linux环境下,用于表示进程间网络通信的特殊文件类型.本质为内核借助缓冲区形成的伪 ...
- vscode项目配置 vue-loader-webpack
使用vsCode进行项目配置 一.准备工作 1.下载Visual Studio Code 下载地址 2.打开vscode,根据自己需求下载相应插件,可以提高工作效率. 点击下角选项(我作了红框标记), ...
- C++中文件读写的操作
在C++中读读写文件一般指的就是磁盘中的文本文件和二进制文件: 文本文件:以字符序列组成的文件 二进制文件:由二进制组成的文件 读写文件采用ofstream和ifstream文件流,两者可用头文件&l ...
- sublime text3 激活码——许可证
亲测: 现在是公元2018年6月4日.晴 ``` ----- BEGIN LICENSE ----- sgbteam Single User License EA7E-1153259 8891CBB9 ...
- PS常用快捷键(收藏)
一.工具箱(多种工具共用一个快捷键的可同时按[Shift]加此快捷键选取) 矩形.椭圆选框工具 [M] 移动工具 [V] 套索.多边形套索.磁性套索 [L] 魔棒工具 [W] 裁剪工具 [C] 切片工 ...