Codeforces Beta Round #31 (Div. 2, Codeforces format)

http://codeforces.com/contest/31

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

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 maxn 1000005
  8. typedef long long ll;
  9. typedef unsigned long long ull;
  10. /*#ifndef ONLINE_JUDGE
  11. freopen("1.txt","r",stdin);
  12. #endif */
  13.  
  14. int a[];
  15.  
  16. int Check(string str){
  17. int pre=-;
  18. int pos=-;
  19. for(int i=;i<str.length();i++){
  20. if(str[i]=='@'){
  21. pos=i;
  22. if(pre<i-&&i+<str.length()){
  23. pre=i+;
  24. }
  25. else{
  26. return -;
  27. }
  28. }
  29. }
  30. return pos;
  31. }
  32.  
  33. int main(){
  34. #ifndef ONLINE_JUDGE
  35. // freopen("1.txt","r",stdin);
  36. #endif
  37. std::ios::sync_with_stdio(false);
  38. string str;
  39. cin>>str;
  40. int pos=Check(str);
  41. if(pos!=-){
  42. for(int i=;i<str.length();i++){
  43. cout<<str[i];
  44. if(str[i]=='@'){
  45.  
  46. if(pos!=i){
  47. cout<<str[i+];
  48. i++;
  49.  
  50. if(i<str.length()-){
  51. cout<<',';
  52. }
  53. }
  54. }
  55. }
  56. }
  57. else cout<<"No solution"<<endl;
  58. }

C

暴力

  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 maxn 1000005
  8. typedef long long ll;
  9. typedef unsigned long long ull;
  10. /*#ifndef ONLINE_JUDGE
  11. freopen("1.txt","r",stdin);
  12. #endif */
  13. struct sair{
  14. int s,e,pos;
  15. }a[];
  16.  
  17. bool cmp(sair a,sair b){
  18. if(a.s==b.s) return a.e<b.e;
  19. return a.s<b.s;
  20. }
  21.  
  22. int main(){
  23. #ifndef ONLINE_JUDGE
  24. // freopen("1.txt","r",stdin);
  25. #endif
  26. std::ios::sync_with_stdio(false);
  27. int n;
  28. cin>>n;
  29. for(int i=;i<n;i++){
  30. cin>>a[i].s>>a[i].e;
  31. a[i].pos=i+;
  32. }
  33. sort(a,a+n,cmp);
  34. vector<int>ans;
  35. int flag;
  36. for(int i=;i<n;i++){
  37. int pre=-;
  38. flag=;
  39. for(int j=;j<n;j++){
  40. if(i!=j){
  41. if(pre==-){
  42. pre=a[j].e;
  43. }
  44. else{
  45. if(pre>a[j].s){
  46. flag=;
  47. }
  48. else{
  49. pre=a[j].e;
  50. }
  51. }
  52. }
  53. }
  54. if(!flag){
  55. ans.pb(a[i].pos);
  56. }
  57. }
  58. cout<<ans.size()<<endl;
  59. sort(ans.begin(),ans.end());
  60. for(int i=;i<ans.size();i++){
  61. cout<<ans[i]<<" ";
  62. }
  63. }

D

bfs求连通块,模拟剪纸的过程

  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 maxn 1000005
  8. typedef long long ll;
  9. typedef unsigned long long ull;
  10. /*#ifndef ONLINE_JUDGE
  11. freopen("1.txt","r",stdin);
  12. #endif */
  13.  
  14. int n,m,k;
  15. int book[][];
  16. int dir[][]={,,,,,-,-,};
  17.  
  18. int bfs(int x,int y){
  19. queue<pair<int,int> >Q;
  20. int ans=;
  21. book[x][y]=;
  22. Q.push(make_pair(x,y));
  23. pair<int,int>p;
  24. while(!Q.empty()){
  25. p=Q.front();
  26. Q.pop();
  27. for(int i=;i<;i++){
  28. int xx=p.first+dir[i][];
  29. int yy=p.second+dir[i][];
  30. if(xx>=&&xx<=*n&&yy>=&&yy<=*m&&!book[xx][yy]){
  31. book[xx][yy]=;
  32. if((xx%)&&(yy%)){
  33. ans++;
  34. }
  35. Q.push(make_pair(xx,yy));
  36. }
  37. }
  38. }
  39. return ans;
  40. }
  41.  
  42. int main(){
  43. #ifndef ONLINE_JUDGE
  44. freopen("1.txt","r",stdin);
  45. #endif
  46. std::ios::sync_with_stdio(false);
  47. cin>>n>>m>>k;
  48. int a,b,c,d;
  49. while(k--){
  50. cin>>a>>b>>c>>d;///边为偶数
  51. a*=,b*=,c*=,d*=;
  52. if(a==c){
  53. if(b>d) swap(b,d);
  54. for(int i=b;i<=d;i++){
  55. book[a][i]=;
  56. }
  57. }
  58. else{
  59. if(a>c) swap(a,c);
  60. for(int i=a;i<=c;i++){
  61. book[i][b]=;
  62. }
  63. }
  64. }
  65. vector<int>ans;
  66. for(int i=;i<=*n;i++){
  67. for(int j=;j<=*m;j++){
  68. if(!book[i][j]&&(i%)&&(j%)){
  69. ans.pb(bfs(i,j));
  70. }
  71. }
  72. }
  73. sort(ans.begin(),ans.end());
  74. for(int i=;i<ans.size();i++){
  75. cout<<ans[i]<<" ";
  76. }
  77. cout<<endl;
  78. }

E

题意:给2*n个数字,A和B各选n个各组成一个数,使得A+B的和最大

DP,细节在代码里

  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 maxn 1000005
  8. typedef long long ll;
  9. typedef unsigned long long ull;
  10. /*#ifndef ONLINE_JUDGE
  11. freopen("1.txt","r",stdin);
  12. #endif */
  13.  
  14. ll dp[][];
  15. ll p[];
  16.  
  17. int main(){
  18. #ifndef ONLINE_JUDGE
  19. // freopen("1.txt","r",stdin);
  20. #endif
  21. std::ios::sync_with_stdio(false);
  22. int n;
  23. string str;
  24. cin>>n;
  25. cin>>str;
  26. int len=*n;
  27. p[]=;
  28. for(int i=;i<=;i++){
  29. p[i]=p[i-]*;
  30. }
  31. ///dp[i][j] 表示A选了i个,B选了j个,dp[i][j]记录的是A+B的和
  32. for(int i=;i<=n;i++){
  33. for(int j=;j<=n;j++){
  34. ll tmp=str[*n-i-j]-'';///从后向前推
  35. if(i){
  36. dp[i][j]=dp[i-][j]+tmp*p[i-];
  37. }
  38. if(j){
  39. dp[i][j]=max(dp[i][j],dp[i][j-]+tmp*p[j-]);
  40. }
  41. cout<<dp[i][j]<<endl;
  42. }
  43. }
  44. int i=n,j=n;
  45. while(i||j){
  46. ll tmp=str[*n-i-j]-'';
  47. if(i>&&(tmp*p[i-]+dp[i-][j]==dp[i][j])){
  48. cout<<'H';
  49. i--;
  50. }
  51. else{
  52. cout<<'M';
  53. j--;
  54. }
  55. }
  56. cout<<endl;
  57. }

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

  1. Codeforces Beta Round #32 (Div. 2, Codeforces format)

    Codeforces Beta Round #32 (Div. 2, Codeforces format) http://codeforces.com/contest/32 A #include< ...

  2. Codeforces Beta Round #29 (Div. 2, Codeforces format)

    Codeforces Beta Round #29 (Div. 2, Codeforces format) http://codeforces.com/contest/29 A #include< ...

  3. Codeforces Beta Round #29 (Div. 2, Codeforces format) C. Mail Stamps 离散化拓扑排序

    C. Mail Stamps Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem ...

  4. Codeforces Beta Round #29 (Div. 2, Codeforces format) C. Mail Stamps 拓扑排序

    C. Mail Stamps     One day Bob got a letter in an envelope. Bob knows that when Berland's post offic ...

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. setTimeout闭包常见问题

    经常会遇到这样的问题,setTimeout按序输出循环数字,而不是最后输出同一个数字: 题目: for (var i = 0; i < 5; i++) { setTimeout(function ...

  2. js模板引擎初级

    模板引擎:模板引擎(这里特指用于Web开发的模板引擎)是为了使用户界面与业务数据(内容)分离而产生的,它可以生成特定格式的文档,用于网站的模板引擎就会生成一个标准的html文档. 模板引擎的实现方式有 ...

  3. Windows常用命令实例

    熟练使用DOS常用命令有助于提高工作效率. 1.windows+R:打开运行程序窗口 2.cmd:调用DOS命令窗口 3.mstsc:调用远程桌面命令窗口.mstsc -v 192.168..0.1 ...

  4. 21 week4 submit buidAndRun() node-rest-client

    . 我们想实现一个提交代码的功能 这个功能有nodeserver 传到后边的server 验证 在返回给nodeserver 我们稍微修改一下ui ATOM修改文件权限不够 用下面命令 我们 Cont ...

  5. Hibernate学习笔记1.1(简单插入数据)

    Hibernate是把以前的jdbc连接数据库的操作进行了一系列友好的封装,最好只用调用save即可,即将sql语句的这部分操作转化为面向对象的 Hibernate资源准备: 文档目录结构: 1.网址 ...

  6. ArcMap导入图层出现General function failure问题 [转]

      ArcMap导入图层出现General function failure问题 [转] Link: http://www.cnblogs.com/angelx/p/3391967.html 问题描述 ...

  7. IT蓝豹强烈推荐:符合1-2年工作经验,开发中的难点及相关优化:

    IT蓝豹强烈推荐:符合1-2年工作经验,开发中的难点及相关优化: IT蓝豹 ------------------> sqlite数据库版本升级 1.sqlite升级步骤: 1.自己写一个类继承自 ...

  8. mysql 数据库必备命令操作,入门练习一下

    mysql 数据库必备命令操作 show databases: 查看所有的数据库: create database jfedu: 创建名为jfedu数据库: use nihao: 进入jfedu数据库 ...

  9. table 合并内容相同的第一列

    function mergeCells() { var tbodyTlth = $("#datatable_ajax1 tbody").find("tr").l ...

  10. webstocket 聊天

    /** * 初始化socket **/ function initSocket(index_host){//端口号 if( !window.WebSocket ){ console.log(" ...