题意:较大的容量减较小的容量,较小的容量翻倍。问操作几回其中一个空。

开始用set判重,重复就不可行。不过状态最多有2e18种。不仅爆内存,还超时。然后找规律。发现只有比例为1:1,1:3,1:7,3:5,1:15,3:13,5:11,7:9......这样才行。也就是化简以后相加是2^k。

  1. #pragma comment(linker,"/STACK:1024000000,1024000000")
  2. #include <iostream>
  3. #include <cstdio>
  4. #include <cmath>
  5. #include <algorithm>
  6. #include <vector>
  7. #include <iomanip>
  8. #include <cstring>
  9. #include <map>
  10. #include <queue>
  11. #include <set>
  12. #include <cassert>
  13. #include <list>
  14. #define mkp make_pair
  15. using namespace std;
  16. const double EPS=1e-;
  17. const int SZ=1e2+,INF=0x7FFFFFFF;
  18. const long long mod=;
  19. typedef long long lon;
  20.  
  21. int gcd(int x,int y)
  22. {
  23. if(x==)return y;
  24. if(y==)return x;
  25. if(x<y)swap(x,y);
  26. int res=;
  27. for(;;)
  28. {
  29. int rem=x%y;
  30. if(rem==)return y;
  31. x=y;
  32. y=rem;
  33. }
  34. }
  35.  
  36. int cnt(int x)
  37. {
  38. int res=;
  39. for(;x;x-=x&-x,++res);
  40. return res;
  41. }
  42.  
  43. int chk(int x)
  44. {
  45. int num=cnt(x);
  46. if(num!=)return -;
  47. else
  48. {
  49. for(int i=;i<;++i)
  50. {
  51. if((<<i)&x)return i;
  52. }
  53. }
  54. }
  55.  
  56. int main()
  57. {
  58. std::ios::sync_with_stdio();
  59. //freopen("d:\\1.txt","r",stdin);
  60. int casenum;
  61. //cin>>casenum;
  62. //scanf("%d",&casenum);
  63. //for(int time=1;time<=casenum;++time)
  64. //for(int time=1;cin>>n;++time)
  65. {
  66. int n,m;
  67. cin>>n>>m;
  68. int d=gcd(n,m);
  69. //cout<<d<<endl;
  70. n/=d,m/=d;
  71. if(n==||m==)cout<<<<endl;
  72. else
  73. {
  74. cout<<chk(n+m)<<endl;
  75. }
  76. }
  77. return ;
  78. }

超内存的:

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cmath>
  4. #include <algorithm>
  5. #include <vector>
  6. #include <iomanip>
  7. #include <cstring>
  8. #include <map>
  9. #include <queue>
  10. #include <set>
  11. #include <cassert>
  12. #include <list>
  13. using namespace std;
  14. const double EPS=1e-;
  15. const int SZ=1e2+,INF=0x7FFFFFFF;
  16. const long long mod=;
  17. typedef long long lon;
  18. int n,sum[],arr[];
  19.  
  20. bool chk(int x,int t)
  21. {
  22. int res=;
  23. if(x/n&&arr[x]<arr[x-n])++res;
  24. if(x%n&&arr[x]<arr[x-])++res;
  25. if(x/n!=n-)
  26. {
  27. if(t)
  28. {
  29. if(arr[x]<arr[x+n])++res;
  30. }
  31. else ++res;
  32. }
  33. if(x%n!=n-)
  34. {
  35. if(t)
  36. {
  37. if(arr[x]<arr[x+])++res;
  38. }
  39. else ++res;
  40. }
  41. return t?res==sum[x]:res>=sum[x];
  42. }
  43.  
  44. bool dfs(int x)
  45. {
  46. //cout<<x<<endl;
  47. if(x==n*n)
  48. {
  49. // for(int i=0;i<n*n;++i)
  50. // {
  51. // cout<<arr[i]<<" ";
  52. // }cout<<endl;
  53. return ;
  54. }
  55. for(int i=;i<;++i)
  56. {
  57. arr[x]=i;
  58. if(x%n&&chk(x-,||((x-)/n==n-))==)continue;
  59. if(x/n&&chk(x-n,)==)continue;
  60. if(x==n*n-&&chk(x,)==)continue;
  61. //cout<<x<<" "<<i<<endl;
  62. if(dfs(x+))return ;
  63. //else cout<<x<<" "<<i<<" fail"<<endl;
  64. }
  65. arr[x]=;
  66. return ;
  67. }
  68.  
  69. int main()
  70. {
  71. std::ios::sync_with_stdio();
  72. //freopen("d:\\1.txt","r",stdin);
  73. int casenum;
  74. //cin>>casenum;
  75. //scanf("%d",&casenum);
  76. //for(int time=1;time<=casenum;++time)
  77. //for(int time=1;cin>>n;++time)
  78. {
  79. cin>>n;
  80. for(int i=;i<n*n;++i)
  81. {
  82. cin>>sum[i];
  83. }
  84. if(n==)
  85. {
  86. if(sum[]==)cout<<<<endl;
  87. else cout<<"NO SOLUTION"<<endl;
  88. }
  89. else if(dfs())
  90. {
  91. for(int i=;i<n*n;++i)
  92. {
  93. if(i%n)cout<<" ";
  94. cout<<arr[i];
  95. if(i%n==n-)cout<<endl;
  96. }
  97. }
  98. else
  99. {
  100. cout<<"NO SOLUTION"<<endl;
  101. }
  102. }
  103. return ;
  104. }

超时的:

  1. #pragma comment(linker,"/STACK:1024000000,1024000000")
  2. #include <iostream>
  3. #include <cstdio>
  4. #include <cmath>
  5. #include <algorithm>
  6. #include <vector>
  7. #include <iomanip>
  8. #include <cstring>
  9. #include <map>
  10. #include <queue>
  11. #include <set>
  12. #include <cassert>
  13. #include <list>
  14. #define mkp make_pair
  15. using namespace std;
  16. const double EPS=1e-;
  17. const int SZ=1e2+,INF=0x7FFFFFFF;
  18. const long long mod=;
  19. typedef long long lon;
  20.  
  21. int work(int x,int y,int x1,int y1,int s)
  22. {
  23. if(x<y)swap(x,y);
  24. if(x1<y1)swap(x1,y1);
  25. //cout<<x<<" "<<y<<" "<<x1<<" "<<y1<<endl;
  26. if(s!=&&x==x1&&y==y1)return -;
  27. x-=y;
  28. y*=;
  29. x1-=y1;
  30. y1*=;
  31. if(x<y)swap(x,y);
  32. if(x1<y1)swap(x1,y1);
  33. //if(s!=1&&x==x1&&y==y1)return -1;
  34. x1-=y1;
  35. y1*=;
  36. if(x==||y==)return s;
  37. return work(x,y,x1,y1,s+);
  38. }
  39.  
  40. int main()
  41. {
  42. std::ios::sync_with_stdio();
  43. //freopen("d:\\1.txt","r",stdin);
  44. int casenum;
  45. //cin>>casenum;
  46. //scanf("%d",&casenum);
  47. //for(int time=1;time<=casenum;++time)
  48. //for(int time=1;cin>>n;++time)
  49. {
  50. int n,m;
  51. cin>>n>>m;
  52. if(n==||m==)cout<<<<endl;
  53. else if((n&)^(m&))cout<<-<<endl;
  54. else cout<<work(n,m,n,m,)<<endl;
  55. }
  56. return ;
  57. }

sgu 126 Boxes的更多相关文章

  1. 找规律 SGU 126 Boxes

    题目地址:http://acm.sgu.ru/problem.php?contest=0&problem=126 /* 找规律,智商不够,看了题解 详细解释:http://blog.csdn. ...

  2. SGU 126 Boxes(模拟题|二进制)

    Translate:Sgu/126 126. 盒子 time limit per test: 0.5 sec. memory limit per test: 4096 KB 有两个盒子. 第一个盒子里 ...

  3. SGU 126. Boxes --- 模拟

    <传送门> 126. Boxes time limit per test: 0.25 sec. memory limit per test: 4096 KB There are two b ...

  4. Boxes - SGU 126(找规律)

    题目大意:有两个箱子,一个箱子装了A个球,一个箱子装了B个球,可以从球多的那个箱子拿出来球少的箱子里面球的总数放在少的那个箱子里面,问能否把球全部放在一个箱子里面? 分析:很容易求出来最后放的拿一下一 ...

  5. SGU 分类

    http://acm.sgu.ru/problemset.php?contest=0&volume=1 101 Domino 欧拉路 102 Coprime 枚举/数学方法 103 Traff ...

  6. 快速切题sgu126. Boxes

    126. Boxes time limit per test: 0.25 sec. memory limit per test: 4096 KB There are two boxes. There ...

  7. 今日SGU 5.4

    SGU 127 题意:给你n个数字,和m,k,问你有多少个数字的m次幂可以被k整除 收获:快速幂 #include<bits/stdc++.h> #define de(x) cout< ...

  8. SGU 495. Kids and Prizes

    水概率....SGU里难得的水题.... 495. Kids and Prizes Time limit per test: 0.5 second(s)Memory limit: 262144 kil ...

  9. SGU Volume 1

    SGU 解题报告(持续更新中...Ctrl+A可看题目类型): SGU101.Domino(多米诺骨牌)------------★★★type:图 SGU102.Coprimes(互质的数) SGU1 ...

随机推荐

  1. tomcat启动失败问题排除及解决办法 Server Tomcat v7.0 Server at localhost failed to start.

    tomcat启动失败问题排除及解决办法 Server Tomcat v7.0 Server at localhost failed to start. 导致上面问题的原因可能有很多种,每种的解决办法都 ...

  2. 用rewrite把旧域名直接跳转到新域名的nginx配置

    用rewrite把旧域名直接跳转到新域名的nginx配置 把下面代码保存到daziran.com.conf 放在nginx配置目录下 /etc/nginx/conf.d/ #把旧域名zdz8207直接 ...

  3. javashop技术培训总结,架构介绍,Eop核心机制

    javashop技术培训一.架构介绍1.Eop核心机制,基于spring的模板引擎.组件机制.上下文管理.数据库操作模板引擎负责站点页面的解析与展示组件机制使得可以在不改变核心代码的情况下实现对应用核 ...

  4. 循环ajax请求问题

    项目开发过程碰到过这种需求:需要循环发送ajax请求,请求参数和循环索引有关.第一次实现的时候用了类似下面的方法,结果发现发送到后端的参数数据都是最后一次循环的索引 for(var i=0; i< ...

  5. 如何用tomcat发布自己的Java项目

    如何用tomcat发布自己的Java项目 tomcat是什么?它是一个免费的开放源代码的Web 应用服务器,属于轻量级应用服务器.我们用Java开发出来的web项目,通过tomcat发布出来,别人就可 ...

  6. QTQuick控件基础(1)

    一.Item QtQuick所有的可视项目都继承自Item,它定义了可视化项目所有通用特性(x\y\width\height\anchors等)具体包括 1.作为容器 2.不透明性 没有设置opaci ...

  7. Python3基础 父,子类普通方法重名 子类方法覆盖父类方法

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  8. jQuery 中 $( ) 函数的用法总结

    摘要 jQuery对象: 具有jquery框架设置的所有功能的调用者, 就是该框架的对象 $又是什么?: $就是jQuery对象, jQuery对象为window的全局属性, 所以可以直接使用 如何自 ...

  9. 字符编码(ASCII、ANSI、GB2312、UTF-8等)系统梳理(转载)

    引言 在显示器上看见的文字.图片等信息在电脑里面其实并不是我们看见的样子,即使你知道所有信息都存储在硬盘里,把它拆开也看不见里面有任何东西,只有些盘片.假设,你用显微镜把盘片放大,会看见盘片表面凹凸不 ...

  10. No compatible targets were found Do you wish to a add new Android Virtual Device ?

    运行一个Android小程序时提示: No compatible targets were found Do you wish to a add new Android Virtual Device ...