Codeforces Beta Round #55 (Div. 2)

http://codeforces.com/contest/59

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 1000005
  9. #define rep(k,i,j) for(int k=i;k<j;k++)
  10. typedef long long ll;
  11. typedef unsigned long long ull;
  12.  
  13. int main(){
  14. #ifndef ONLINE_JUDGE
  15. // freopen("input.txt","r",stdin);
  16. #endif
  17. std::ios::sync_with_stdio(false);
  18. string str;
  19. cin>>str;
  20. int big=,small=;
  21. for(int i=;i<str.length();i++){
  22. if(str[i]>='A'&&str[i]<='Z'){
  23. big++;
  24. }
  25. else{
  26. small++;
  27. }
  28. }
  29. if(big<=small){
  30. for(int i=;i<str.length();i++){
  31. if(str[i]>='A'&&str[i]<='Z'){
  32. str[i]+=;
  33. }
  34. cout<<str[i];
  35. }
  36. }
  37. else{
  38. for(int i=;i<str.length();i++){
  39. if(str[i]>='a'&&str[i]<='z'){
  40. str[i]-=;
  41. }
  42. cout<<str[i];
  43. }
  44. }
  45. }

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 1000005
  9. #define rep(k,i,j) for(int k=i;k<j;k++)
  10. typedef long long ll;
  11. typedef unsigned long long ull;
  12.  
  13. int a[];
  14.  
  15. int main(){
  16. #ifndef ONLINE_JUDGE
  17. // freopen("input.txt","r",stdin);
  18. #endif
  19. std::ios::sync_with_stdio(false);
  20. int n;
  21. cin>>n;
  22. int ans=;
  23. int sum=;
  24. int ji=0x3f3f3f3f,ou=0x3f3f3f3f;
  25. for(int i=;i<=n;i++){
  26. cin>>a[i];
  27. if(a[i]%&&a[i]<ji) ji=a[i];
  28. if((a[i]%==)&&a[i]<ou) ou=a[i];
  29. sum+=a[i];
  30. }
  31. if(sum%)cout<<sum<<endl;
  32. else{
  33. if(ji!=0x3f3f3f3f) cout<<sum-ji<<endl;
  34. else cout<<<<endl;
  35. }
  36. }

C

模拟,找出前str.length()/2中,str[i]=='?'&&str[str.length()-1-i]=='?'的个数,然后贪心

  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 1000005
  9. #define rep(k,i,j) for(int k=i;k<j;k++)
  10. typedef long long ll;
  11. typedef unsigned long long ull;
  12.  
  13. int main(){
  14. #ifndef ONLINE_JUDGE
  15. freopen("input.txt","r",stdin);
  16. #endif
  17. std::ios::sync_with_stdio(false);
  18. int n;
  19. map<char,int>mp;
  20. string str;
  21. cin>>n>>str;
  22. int prex=,prey=;
  23. int num=;
  24. rep(i,,str.length()){
  25. if(str[i]!='?')
  26. mp[str[i]]=;
  27. }
  28. int len=str.length()+;
  29. int L=len-;
  30. len/=;
  31. rep(i,,len){
  32. if(str[i]=='?'&&str[L-i-]=='?') num++;
  33. }
  34. int k=n-mp.size();
  35. rep(i,,len){
  36. if(num<k){
  37. cout<<"IMPOSSIBLE"<<endl;
  38. return ;
  39. }
  40. if(i==L-i-){
  41. if(str[i]=='?'){
  42. if(num->=k){
  43. if(mp['a']){
  44. str[i]='a';
  45. num--;
  46. }
  47. else{
  48. str[i]='a';
  49. mp['a']=;
  50. num--;
  51. k--;
  52. }
  53. }
  54. else if(num->=k-){
  55. int flag=;
  56. rep(j,,){
  57. if(mp[char(j+'a')]==){
  58. mp[char(j+'a')]=;
  59. num--;
  60. k--;
  61. str[i]=char(j+'a');
  62. flag=;
  63. break;
  64. }
  65. }
  66. if(flag){
  67. cout<<"IMPOSSIBLE"<<endl;
  68. return ;
  69. }
  70. }
  71. else{
  72. cout<<"IMPOSSIBLE"<<endl;
  73. return ;
  74. }
  75. }
  76. }
  77. else if(str[i]=='?'&&str[L-i-]!='?'){
  78. str[i]=str[L-i-];
  79. }
  80. else if(str[i]!='?'&&str[L-i-]=='?'){
  81. str[L-i-]=str[i];
  82. }
  83. else if(str[i]=='?'&&str[L-i-]=='?'){
  84. prex=i,prey=L-i-;
  85. if(num->=k){
  86. if(mp['a']){
  87. str[i]='a';
  88. str[L-i-]='a';
  89. num-=;
  90. }
  91. else{
  92. mp['a']=;
  93. k--;
  94. num-=;
  95. str[i]='a';
  96. str[L-i-]='a';
  97. }
  98. }
  99. else if(num->=k-){
  100. int flag=;
  101. rep(j,,){
  102. if(mp[char(j+'a')]==){
  103. mp[char(j+'a')]=;
  104. k--;
  105. num-=;
  106. str[i]=char(j+'a');
  107. str[L-i-]=char(j+'a');
  108. flag=;
  109. break;
  110. }
  111. }
  112. if(flag){
  113. cout<<"IMPOSSIBLE"<<endl;
  114. return ;
  115. }
  116. }
  117. else{
  118. cout<<"IMPOSSIBLE"<<endl;
  119. return ;
  120. }
  121. }
  122. else if(str[i]!='?'&&str[L-i-]!='?'){
  123. if(str[i]!=str[L-i-]){
  124. cout<<"IMPOSSIBLE"<<endl;
  125. return ;
  126. }
  127. }
  128. }
  129. // cout<<k<<endl;
  130. // cout<<prex<<" "<<prey<<endl;
  131. if(k==){
  132. int flag=;
  133. rep(i,,){
  134. if(mp[char(i+'a')]==){
  135. str[prex]=char(i+'a');
  136. str[prey]=char(i+'a');
  137. flag=;
  138. break;
  139. k--;
  140. }
  141. }
  142. if(flag){
  143. cout<<"IMPOSSIBLE"<<endl;
  144. return ;
  145. }
  146. }
  147. cout<<str<<endl;
  148. }

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 1000005
  9. #define rep(k,i,j) for(int k=i;k<j;k++)
  10. typedef long long ll;
  11. typedef unsigned long long ull;
  12.  
  13. int a[],b[];
  14. int book[];
  15.  
  16. int main(){
  17. #ifndef ONLINE_JUDGE
  18. freopen("input.txt","r",stdin);
  19. #endif
  20. std::ios::sync_with_stdio(false);
  21. int n;
  22. cin>>n;
  23. rep(i,,*n) cin>>b[i];
  24. rep(i,,*n) cin>>a[i];
  25. int k;
  26. cin>>k;
  27. int pos=,group,pp=;
  28. while(a[pos]!=k) pos++;
  29. group=pos/+;
  30. rep(i,,*(group-)) book[a[i]]=true;
  31. rep(i,,*n) if(!book[b[i]]){
  32. pp=i;break;
  33. }
  34. if(a[pos]!=b[pp]) sort(a,a+*n);
  35. else{
  36. int flag=-;
  37. rep(i,*(group-),*group) if(i!=pos) flag=max(flag,a[i]);
  38. sort(a,a+*group);
  39. int pos=;
  40. while(a[pos]!=flag) pos++;
  41. sort(a+pos+,a+*n);
  42. }
  43. rep(i,,*n) if(a[i]!=k) cout<<a[i]<<" ";
  44. }

E

用bfs找最短路,book[i][j]表示当前走到j,它的前一步是在i位置,然后book[i][j]记录的是它的前一步在队列中的位置

  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 1000005
  9. #define rep(k,i,j) for(int k=i;k<j;k++)
  10. typedef long long ll;
  11. typedef unsigned long long ull;
  12.  
  13. vector<int>ve[];
  14. int book[][];
  15. int n,m,k;
  16. set< pair<int,pair<int,int> > >se;
  17. set< pair<int,pair<int,int> > >::iterator it;
  18.  
  19. struct sair{
  20. int pre,now,step;
  21. }Q[];
  22.  
  23. int bfs(){
  24. sair s,e;
  25. s.pre=,s.now=,s.step=;
  26. int L=,R=;
  27. Q[R++]=s;
  28. int u;
  29. while(L<R){
  30. s=Q[L++];
  31. rep(i,,ve[s.now].size()){
  32. u=ve[s.now][i];
  33. if(!book[s.now][u]){
  34. it=se.find(make_pair(s.pre,make_pair(s.now,u)));
  35. if(it==se.end()){
  36. e.pre=s.now;
  37. e.now=u;
  38. e.step=s.step+;
  39. book[e.pre][e.now]=L-;
  40. Q[R++]=e;
  41.  
  42. if(u==n){
  43. cout<<e.step<<endl;
  44. return R-;
  45. }
  46.  
  47. }
  48. }
  49. }
  50. }
  51. return ;
  52. }
  53.  
  54. void dfs(int pos){
  55. if(pos==) exit();
  56. if(pos==){
  57. cout<<Q[pos].now<<" ";
  58. return;
  59. }
  60. dfs(book[Q[pos].pre][Q[pos].now]);
  61. cout<<Q[pos].now<<" ";
  62. }
  63.  
  64. int main(){
  65. #ifndef ONLINE_JUDGE
  66. freopen("input.txt","r",stdin);
  67. #endif
  68. std::ios::sync_with_stdio(false);
  69. cin>>n>>m>>k;
  70. int u,v;
  71. rep(i,,m){
  72. cin>>u>>v;
  73. ve[u].pb(v);
  74. ve[v].pb(u);
  75. }
  76. int w;
  77. rep(i,,k){
  78. cin>>u>>v>>w;
  79. se.insert(make_pair(u,make_pair(v,w)));
  80. }
  81. int pos=bfs();
  82. if(!pos) cout<<-<<endl;
  83. else{
  84. dfs(pos);
  85. }
  86. }

Codeforces Beta Round #55 (Div. 2)的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. Redis 密码

  2. Navicat Premium 12安装与激活

    https://www.jianshu.com/p/42a33b0dda9c 若使用Navicat Premium 12.1.10.0请转至Navicat Premium 12.1.10.0安装与激活 ...

  3. Cache专用: SoftReference

    SoftReference的语义就是当内存不够用的时候,GC会回收SoftReference所引用的对象.所以,在memory sensitive的程序中将某些大型数据设置成SoftReference ...

  4. 机器学习进阶-图像金字塔与轮廓检测-轮廓检测 1.cv2.cvtColor(图像颜色转换) 2.cv2.findContours(找出图像的轮廓) 3.cv2.drawContours(画出图像轮廓) 4.cv2.contourArea(轮廓面积) 5.cv2.arcLength(轮廓周长) 6.cv2.aprroxPloyDP(获得轮廓近似) 7.cv2.boudingrect(外接圆)..

    1. cv2.cvtcolor(img, cv2.COLOR_BGR2GRAY) # 将彩色图转换为灰度图 参数说明: img表示输入的图片, cv2.COLOR_BGR2GRAY表示颜色的变换形式 ...

  5. 2018SDIBT_国庆个人第二场

    A.codeforces1038A You are given a string ss of length nn, which consists only of the first kk letter ...

  6. 1:python 简介与基础

    什么是python? 1.python是一种面向对象的解释型语言,它继承了传统编译语言的通用性和强大性,同时也借鉴了简单脚本和解释语言的易用性. 2.python 在自动化测试.人工智能.数据分析等方 ...

  7. [C语言]变量VS常量

    -------------------------------------------------------------------------------------------- 1. 固定不变 ...

  8. Ajax 学习 第四篇

    使用jQuery实现Ajax 跨域

  9. ubuntu16.04 64bit 升级到 python3.6

    https://blog.csdn.net/zhao__zhen/article/details/81584933 https://www.codetd.com/article/1967538 htt ...

  10. linux下的arm汇编程序

    1.gnu 的编译环境搭建 解压编译工具,加入环境变量PATH 2.编译相关命令的使用 编译命令 arm-linux-gcc  -g -c -o led.o main.o led.c main.c / ...