Codeforces Beta Round #70 (Div. 2)

http://codeforces.com/contest/78

A

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define lson l,mid,rt<<1
  4. #define rson mid+1,r,rt<<1|1
  5. #define sqr(x) ((x)*(x))
  6. #define pb push_back
  7. #define eb emplace_back
  8. #define maxn 1000006
  9. #define eps 1e-8
  10. #define pi acos(-1.0)
  11. #define rep(k,i,j) for(int k=i;k<j;k++)
  12. typedef long long ll;
  13. typedef unsigned long long ull;
  14.  
  15. map<char,int>mp;
  16.  
  17. int main(){
  18. #ifndef ONLINE_JUDGE
  19. // freopen("input.txt","r",stdin);
  20. #endif
  21. std::ios::sync_with_stdio(false);
  22. mp['a']=,mp['e']=,mp['i']=,mp['o']=,mp['u']=;
  23. string str;
  24. getline(cin,str);
  25. int num=;
  26. for(int i=;i<str.length();i++){
  27. num+=mp[str[i]];
  28. }
  29. if(num==){
  30. getline(cin,str);
  31. num=;
  32. for(int i=;i<str.length();i++){
  33. num+=mp[str[i]];
  34. }
  35. if(num==){
  36. getline(cin,str);
  37. num=;
  38. for(int i=;i<str.length();i++){
  39. num+=mp[str[i]];
  40. }
  41. if(num==) {
  42. cout<<"YES"<<endl;
  43. return ;
  44.  
  45. }
  46. }
  47.  
  48. }
  49. cout<<"NO"<<endl;
  50. }

B

找规律

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define lson l,mid,rt<<1
  4. #define rson mid+1,r,rt<<1|1
  5. #define sqr(x) ((x)*(x))
  6. #define pb push_back
  7. #define eb emplace_back
  8. #define maxn 1000006
  9. #define eps 1e-8
  10. #define pi acos(-1.0)
  11. #define rep(k,i,j) for(int k=i;k<j;k++)
  12. typedef long long ll;
  13. typedef unsigned long long ull;
  14.  
  15. map<char,int>mp;
  16.  
  17. int main(){
  18. #ifndef ONLINE_JUDGE
  19. // freopen("input.txt","r",stdin);
  20. #endif
  21. std::ios::sync_with_stdio(false);
  22. int n;
  23. cin>>n;
  24. cout<<"ROYGBIV";
  25. n-=;
  26. for(int i=;i<n;i++){
  27. if(i%==){
  28. cout<<"G";
  29. }
  30. else if(i%==){
  31. cout<<"B";
  32. }
  33. else if(i%==){
  34. cout<<"I";
  35. }
  36. else {
  37. cout<<"V";
  38. }
  39. }
  40. }

C

博弈 如果n是偶数的话,后手必胜,因为他可以模仿先手,如果n是奇数的话,判断先手能否完成切割任务

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define lson l,mid,rt<<1
  4. #define rson mid+1,r,rt<<1|1
  5. #define sqr(x) ((x)*(x))
  6. #define pb push_back
  7. #define eb emplace_back
  8. #define maxn 1000006
  9. #define eps 1e-8
  10. #define pi acos(-1.0)
  11. #define rep(k,i,j) for(int k=i;k<j;k++)
  12. typedef long long ll;
  13. typedef unsigned long long ull;
  14.  
  15. map<char,int>mp;
  16. int n,m,k;
  17. bool panduan(){
  18. int sq=sqrt(m);
  19. for(int i=;i<=sq;i++){
  20. if(m%i==){
  21. if(i>=k&&m/i>) return ;
  22. else if(i>&&m/i>=k) return ;
  23. }
  24. }
  25. return ;
  26.  
  27. }
  28.  
  29. int main(){
  30. #ifndef ONLINE_JUDGE
  31. // freopen("input.txt","r",stdin);
  32. #endif
  33. std::ios::sync_with_stdio(false);
  34. cin>>n>>m>>k;
  35. if(n%==) cout<<"Marsel";
  36. else {
  37. if(panduan()){
  38. cout<<"Timur";
  39. }
  40. else{
  41. cout<<"Marsel";
  42. }
  43.  
  44. }
  45. }

D

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define lson l,mid,rt<<1
  4. #define rson mid+1,r,rt<<1|1
  5. #define sqr(x) ((x)*(x))
  6. #define pb push_back
  7. #define eb emplace_back
  8. #define maxn 1000006
  9. #define eps 1e-8
  10. #define pi acos(-1.0)
  11. #define rep(k,i,j) for(int k=i;k<j;k++)
  12. typedef long long ll;
  13. typedef unsigned long long ull;
  14.  
  15. map<char,int>mp;
  16. int n,m,k;
  17.  
  18. int main(){
  19. #ifndef ONLINE_JUDGE
  20. // freopen("input.txt","r",stdin);
  21. #endif
  22. std::ios::sync_with_stdio(false);
  23. ll n;
  24. cin>>n;
  25. ll ans=;
  26. for(double i=8.0/;i<*n/sqrt();i+=){
  27. double tmp=(sqrt(16.0*n*n/-*i*i)-i)/2.0-2.0/;
  28. if(tmp>) ans+=(ll)tmp/+;
  29. }
  30. cout<<ans*+<<endl;
  31. }

E

最大流。先标记毒气到达每个实验室的时间,再判断科学家能否在毒气或规定时间内到达救生仓,然后建图

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define lson l,mid,rt<<1
  4. #define rson mid+1,r,rt<<1|1
  5. #define sqr(x) ((x)*(x))
  6. #define pb push_back
  7. #define eb emplace_back
  8. #define maxn 1000006
  9. #define eps 1e-8
  10. #define pi acos(-1.0)
  11. #define rep(k,i,j) for(int k=i;k<j;k++)
  12. typedef long long ll;
  13. typedef unsigned long long ull;
  14. #define MAXN 200005
  15. const int N=;
  16. const int M=;
  17. const int INF=0x3f3f3f3f;
  18. using namespace std;
  19. int n;
  20. struct Edge{
  21. int v,next;
  22. int cap,flow;
  23. }edge[MAXN*];//注意这里要开的够大。。不然WA在这里真的想骂人。。问题是还不报RE。。
  24. int cur[MAXN],pre[MAXN],gap[MAXN],path[MAXN],dep[MAXN];
  25. int cnt=;//实际存储总边数
  26. void isap_init()
  27. {
  28. cnt=;
  29. memset(pre,-,sizeof(pre));
  30. }
  31. void isap_add(int u,int v,int w)//加边
  32. {
  33. edge[cnt].v=v;
  34. edge[cnt].cap=w;
  35. edge[cnt].flow=;
  36. edge[cnt].next=pre[u];
  37. pre[u]=cnt++;
  38. }
  39. void add(int u,int v,int w){
  40. isap_add(u,v,w);
  41. isap_add(v,u,);
  42. }
  43. bool bfs(int s,int t)//其实这个bfs可以融合到下面的迭代里,但是好像是时间要长
  44. {
  45. memset(dep,-,sizeof(dep));
  46. memset(gap,,sizeof(gap));
  47. gap[]=;
  48. dep[t]=;
  49. queue<int>q;
  50. while(!q.empty()) q.pop();
  51. q.push(t);//从汇点开始反向建层次图
  52. while(!q.empty())
  53. {
  54. int u=q.front();
  55. q.pop();
  56. for(int i=pre[u];i!=-;i=edge[i].next)
  57. {
  58. int v=edge[i].v;
  59. if(dep[v]==-&&edge[i^].cap>edge[i^].flow)//注意是从汇点反向bfs,但应该判断正向弧的余量
  60. {
  61. dep[v]=dep[u]+;
  62. gap[dep[v]]++;
  63. q.push(v);
  64. // if(v==sp)//感觉这两句优化加了一般没错,但是有的题可能会错,所以还是注释出来,到时候视情况而定
  65. // break;
  66. }
  67. }
  68. }
  69. return dep[s]!=-;
  70. }
  71. int isap(int s,int t)
  72. {
  73. if(!bfs(s,t)) return ;
  74. memcpy(cur,pre,sizeof(pre));
  75. //for(int i=1;i<=n;i++)
  76. //cout<<"cur "<<cur[i]<<endl;
  77. int u=s;
  78. path[u]=-;
  79. int ans=;
  80. while(dep[s]<n)//迭代寻找增广路,n为节点数
  81. {
  82. if(u==t)
  83. {
  84. int f=INF;
  85. for(int i=path[u];i!=-;i=path[edge[i^].v])//修改找到的增广路
  86. f=min(f,edge[i].cap-edge[i].flow);
  87. for(int i=path[u];i!=-;i=path[edge[i^].v])
  88. {
  89. edge[i].flow+=f;
  90. edge[i^].flow-=f;
  91. }
  92. ans+=f;
  93. u=s;
  94. continue;
  95. }
  96. bool flag=false;
  97. int v;
  98. for(int i=cur[u];i!=-;i=edge[i].next)
  99. {
  100. v=edge[i].v;
  101. if(dep[v]+==dep[u]&&edge[i].cap-edge[i].flow)
  102. {
  103. cur[u]=path[v]=i;//当前弧优化
  104. flag=true;
  105. break;
  106. }
  107. }
  108. if(flag)
  109. {
  110. u=v;
  111. continue;
  112. }
  113. int x=n;
  114. if(!(--gap[dep[u]]))return ans;//gap优化
  115. for(int i=pre[u];i!=-;i=edge[i].next)
  116. {
  117. if(edge[i].cap-edge[i].flow&&dep[edge[i].v]<x)
  118. {
  119. x=dep[edge[i].v];
  120. cur[u]=i;//常数优化
  121. }
  122. }
  123. dep[u]=x+;
  124. gap[dep[u]]++;
  125. if(u!=s)//当前点没有增广路则后退一个点
  126. u=edge[path[u]^].v;
  127. }
  128. return ans;
  129. }
  130.  
  131. int t;
  132.  
  133. string people[],cap[];
  134. int book[][];
  135. struct sair{
  136. int x,y,step;
  137. };
  138. int dir[][]={,,,,,-,-,};
  139.  
  140. void bfs1(int x,int y){
  141. sair s,e;
  142. s.step=,s.x=x,s.y=y;
  143. memset(book,-,sizeof(book));
  144. queue<sair>Q;
  145. Q.push(s);
  146. book[s.x][s.y]=;
  147. while(!Q.empty()){
  148. s=Q.front();
  149. Q.pop();
  150. if(s.step>=t) break;
  151. for(int i=;i<;i++){
  152. e.x=s.x+dir[i][];
  153. e.y=s.y+dir[i][];
  154. if(e.x>=&&e.x<n&&e.y>=&&e.y<n&&book[e.x][e.y]==-&&people[e.x][e.y]!='Y'){
  155. e.step=s.step+;
  156. book[e.x][e.y]=e.step;
  157. Q.push(e);
  158. }
  159. }
  160. }
  161. }
  162.  
  163. void bfs2(int x,int y){
  164. sair s,e;
  165. int tmp[][];
  166. memset(tmp,-,sizeof(tmp));
  167. s.x=x,s.y=y,s.step=;
  168. tmp[s.x][s.y]=;
  169. queue<sair>Q;
  170. Q.push(s);
  171. int w=people[x][y]-'';
  172. add(s.x*n+s.y,s.x*n+s.y+n*n,w);
  173. while(!Q.empty()){
  174. s=Q.front();
  175. Q.pop();
  176. if(s.step>=t) break;
  177. for(int i=;i<;i++){
  178. e.x=s.x+dir[i][];
  179. e.y=s.y+dir[i][];
  180. if(e.x<||e.x>=n||e.y<||e.y>=n||people[e.x][e.y]=='Z'||people[e.x][e.y]=='Y') continue;
  181. if(tmp[e.x][e.y]==-&&(book[e.x][e.y]==-||book[e.x][e.y]>=s.step+)){
  182. if(book[e.x][e.y]==s.step+){
  183. if(cap[e.x][e.y]>=''&&cap[e.x][e.y]<=''){
  184. add(x*n+y,e.x*n+e.y+n*n,w);
  185. }
  186. }
  187. else{
  188. e.step=s.step+;
  189. tmp[e.x][e.y]=e.step;
  190. add(x*n+y,e.x*n+e.y+n*n,w);
  191. Q.push(e);
  192. }
  193. }
  194. }
  195. }
  196. }
  197.  
  198. int main(){
  199. #ifndef ONLINE_JUDGE
  200. // freopen("input.txt","r",stdin);
  201. #endif
  202. std::ios::sync_with_stdio(false);
  203. cin>>n>>t;
  204. int sx,sy;
  205. isap_init();
  206. for(int i=;i<n;i++){
  207. cin>>people[i];
  208. for(int j=;j<n;j++){
  209. if(people[i][j]=='Z'){
  210. sx=i,sy=j;
  211. }
  212. }
  213. }
  214. for(int i=;i<n;i++) cin>>cap[i];
  215. bfs1(sx,sy);
  216. for(int i=;i<n;i++){
  217. for(int j=;j<n;j++){
  218. if(people[i][j]>=''&&people[i][j]<=''){
  219. bfs2(i,j);
  220. }
  221. }
  222. }
  223. int S=n*n*;
  224. int T=n*n*+;
  225. for(int i=;i<n;i++){
  226. for(int j=;j<n;j++){
  227. if(people[i][j]>=''&&people[i][j]<=''){
  228. add(S,i*n+j,people[i][j]-'');
  229. }
  230. if(cap[i][j]>=''&&cap[i][j]<=''){
  231. add(i*n+j+n*n,T,cap[i][j]-'');
  232. }
  233. }
  234. }
  235. n=n*n*+;
  236. int ans=isap(S,T);
  237. cout<<ans<<endl;
  238. }

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. WPF 透明窗体

    窗体属性中设置:Background="Transparent" AllowsTransparency="True" WindowStyle="Non ...

  2. Java 基础 - 对象池

    对象池  优点:  防止过多的创建对象合理利用对象, 缺点: 会有线程阻塞 Demo 测试代码 package com.cjcx.pay.obj; import java.util.Enumerati ...

  3. java-部分精选面试题

    JVM的类加载机制是什么?有哪些实现方式? 类加载机制: 类的加载指的是将类的.class文件中的二进制数据读入到内存中,将其放在运行时数据区的方法去内,然后在堆区创建一个java.lang.Clas ...

  4. Python3.7中urllib.urlopen 报错问题

    import urllib web = urllib.urlopen('https://www.baidu.com') f = web.read() print(f) 报错: Traceback (m ...

  5. B树、B-树、B+树、B*树的定义和区分

    MySQL是基于B+树聚集索引组织表 B树 即二叉搜索树: 1.所有非叶子结点至多拥有两个儿子(Left和Right): 2.所有结点存储一个关键字: 3.非叶子结点的左指针指向小于其关键字的子树,右 ...

  6. Shell条件表达式

    Shell编程中经常需要判断文件状态.字符串是否相等以及两个数值大小等情况,基于这些比较结果再做执行相关操作.本文主要讲述文件状态.字符串.数值大小的判断比较方法. 文件状态判断 文件状态的判断通常使 ...

  7. C++多态,虚函数,虚函数表,纯虚函数

    1.多态性   指相同对象收到不同消息或不同对象收到相同消息时产生不同的实现动作. C++支持两种多态性:编译时多态性,运行时多态性.    a.编译时多态性:通过重载函数实现 ,模板(2次编译)  ...

  8. 使用__all__限制模块可被导入对象

    经常我们会编写自定义模块,用于被别的脚本调用;有时候为了方便,会使用from module_name import *的方式导入,这样会把模块中全部对象导入进来; 使用__all__结合列表,可以控制 ...

  9. python opencv3 给图片加中文

    转自:https://www.cnblogs.com/arkenstone/p/6961453.html opencv3.2将中文输出到图片上 opencv自带的putText函数无法输出utf8类型 ...

  10. requests库的文档--快速上手

    快速上手 迫不及待了吗?本页内容为如何入门 Requests 提供了很好的指引.其假设你已经安装了 Requests.如果还没有,去安装一节看看吧. 首先,确认一下: Requests 已安装 Req ...