sgu 126 Boxes
题意:较大的容量减较小的容量,较小的容量翻倍。问操作几回其中一个空。
开始用set判重,重复就不可行。不过状态最多有2e18种。不仅爆内存,还超时。然后找规律。发现只有比例为1:1,1:3,1:7,3:5,1:15,3:13,5:11,7:9......这样才行。也就是化简以后相加是2^k。
#pragma comment(linker,"/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
#include <list>
#define mkp make_pair
using namespace std;
const double EPS=1e-;
const int SZ=1e2+,INF=0x7FFFFFFF;
const long long mod=;
typedef long long lon; int gcd(int x,int y)
{
if(x==)return y;
if(y==)return x;
if(x<y)swap(x,y);
int res=;
for(;;)
{
int rem=x%y;
if(rem==)return y;
x=y;
y=rem;
}
} int cnt(int x)
{
int res=;
for(;x;x-=x&-x,++res);
return res;
} int chk(int x)
{
int num=cnt(x);
if(num!=)return -;
else
{
for(int i=;i<;++i)
{
if((<<i)&x)return i;
}
}
} int main()
{
std::ios::sync_with_stdio();
//freopen("d:\\1.txt","r",stdin);
int casenum;
//cin>>casenum;
//scanf("%d",&casenum);
//for(int time=1;time<=casenum;++time)
//for(int time=1;cin>>n;++time)
{
int n,m;
cin>>n>>m;
int d=gcd(n,m);
//cout<<d<<endl;
n/=d,m/=d;
if(n==||m==)cout<<<<endl;
else
{
cout<<chk(n+m)<<endl;
}
}
return ;
}
超内存的:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
#include <list>
using namespace std;
const double EPS=1e-;
const int SZ=1e2+,INF=0x7FFFFFFF;
const long long mod=;
typedef long long lon;
int n,sum[],arr[]; bool chk(int x,int t)
{
int res=;
if(x/n&&arr[x]<arr[x-n])++res;
if(x%n&&arr[x]<arr[x-])++res;
if(x/n!=n-)
{
if(t)
{
if(arr[x]<arr[x+n])++res;
}
else ++res;
}
if(x%n!=n-)
{
if(t)
{
if(arr[x]<arr[x+])++res;
}
else ++res;
}
return t?res==sum[x]:res>=sum[x];
} bool dfs(int x)
{
//cout<<x<<endl;
if(x==n*n)
{
// for(int i=0;i<n*n;++i)
// {
// cout<<arr[i]<<" ";
// }cout<<endl;
return ;
}
for(int i=;i<;++i)
{
arr[x]=i;
if(x%n&&chk(x-,||((x-)/n==n-))==)continue;
if(x/n&&chk(x-n,)==)continue;
if(x==n*n-&&chk(x,)==)continue;
//cout<<x<<" "<<i<<endl;
if(dfs(x+))return ;
//else cout<<x<<" "<<i<<" fail"<<endl;
}
arr[x]=;
return ;
} int main()
{
std::ios::sync_with_stdio();
//freopen("d:\\1.txt","r",stdin);
int casenum;
//cin>>casenum;
//scanf("%d",&casenum);
//for(int time=1;time<=casenum;++time)
//for(int time=1;cin>>n;++time)
{
cin>>n;
for(int i=;i<n*n;++i)
{
cin>>sum[i];
}
if(n==)
{
if(sum[]==)cout<<<<endl;
else cout<<"NO SOLUTION"<<endl;
}
else if(dfs())
{
for(int i=;i<n*n;++i)
{
if(i%n)cout<<" ";
cout<<arr[i];
if(i%n==n-)cout<<endl;
}
}
else
{
cout<<"NO SOLUTION"<<endl;
}
}
return ;
}
超时的:
#pragma comment(linker,"/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
#include <list>
#define mkp make_pair
using namespace std;
const double EPS=1e-;
const int SZ=1e2+,INF=0x7FFFFFFF;
const long long mod=;
typedef long long lon; int work(int x,int y,int x1,int y1,int s)
{
if(x<y)swap(x,y);
if(x1<y1)swap(x1,y1);
//cout<<x<<" "<<y<<" "<<x1<<" "<<y1<<endl;
if(s!=&&x==x1&&y==y1)return -;
x-=y;
y*=;
x1-=y1;
y1*=;
if(x<y)swap(x,y);
if(x1<y1)swap(x1,y1);
//if(s!=1&&x==x1&&y==y1)return -1;
x1-=y1;
y1*=;
if(x==||y==)return s;
return work(x,y,x1,y1,s+);
} int main()
{
std::ios::sync_with_stdio();
//freopen("d:\\1.txt","r",stdin);
int casenum;
//cin>>casenum;
//scanf("%d",&casenum);
//for(int time=1;time<=casenum;++time)
//for(int time=1;cin>>n;++time)
{
int n,m;
cin>>n>>m;
if(n==||m==)cout<<<<endl;
else if((n&)^(m&))cout<<-<<endl;
else cout<<work(n,m,n,m,)<<endl;
}
return ;
}
sgu 126 Boxes的更多相关文章
- 找规律 SGU 126 Boxes
题目地址:http://acm.sgu.ru/problem.php?contest=0&problem=126 /* 找规律,智商不够,看了题解 详细解释:http://blog.csdn. ...
- SGU 126 Boxes(模拟题|二进制)
Translate:Sgu/126 126. 盒子 time limit per test: 0.5 sec. memory limit per test: 4096 KB 有两个盒子. 第一个盒子里 ...
- SGU 126. Boxes --- 模拟
<传送门> 126. Boxes time limit per test: 0.25 sec. memory limit per test: 4096 KB There are two b ...
- Boxes - SGU 126(找规律)
题目大意:有两个箱子,一个箱子装了A个球,一个箱子装了B个球,可以从球多的那个箱子拿出来球少的箱子里面球的总数放在少的那个箱子里面,问能否把球全部放在一个箱子里面? 分析:很容易求出来最后放的拿一下一 ...
- SGU 分类
http://acm.sgu.ru/problemset.php?contest=0&volume=1 101 Domino 欧拉路 102 Coprime 枚举/数学方法 103 Traff ...
- 快速切题sgu126. Boxes
126. Boxes time limit per test: 0.25 sec. memory limit per test: 4096 KB There are two boxes. There ...
- 今日SGU 5.4
SGU 127 题意:给你n个数字,和m,k,问你有多少个数字的m次幂可以被k整除 收获:快速幂 #include<bits/stdc++.h> #define de(x) cout< ...
- SGU 495. Kids and Prizes
水概率....SGU里难得的水题.... 495. Kids and Prizes Time limit per test: 0.5 second(s)Memory limit: 262144 kil ...
- SGU Volume 1
SGU 解题报告(持续更新中...Ctrl+A可看题目类型): SGU101.Domino(多米诺骨牌)------------★★★type:图 SGU102.Coprimes(互质的数) SGU1 ...
随机推荐
- Javassist注解(Annotation)的使用:CXF WebService动态生成
设计一个对接系统,通过动态模型的增删改触发业务系统相应服务的调用.模型增删改方法动态发布为WebService服务.WebService服务采用CXF发布,动态类生成采用Javassist.由于Web ...
- Linux服务器---apache配置文件
Apache配置文件 Apache的配置文件默认路径是“/etc/httpd/conf/httpd.conf”,编辑该文件就可以修改Apache的配置 1.设置网页主目录,参数DocumentRoot ...
- 又一国产855旗舰突然现身:支持5G
12月28日消息,中国联通官方微博放出了vivo NEX 5G版样机.如图所示,该机搭载骁龙855移动平台及X50 5G调制解调器. 早在8月30日,vivo就宣布完成了面向商用5G智能手机的软硬件开 ...
- 如何在Linux环境下通过uwgsi部署Python服务
部署python程序时常常会遇到同一台服务器上2.x和3.x共存的情况,不同应用需要使用不用的python版本,使用virtualenv创建虚拟环境能很好地解决这一问题. 首先,需要在服务器上安装vi ...
- P3501 [POI2010]ANT-Antisymmetry
P3501 [POI2010]ANT-Antisymmetry 二分+hash 注意:答案超出int范围 ------------ 先拿一个反对称串来做栗子:010101 我们可以发现 0101(左边 ...
- C++设计模式 之 “组件协作”模式:Template Method、Strategy、Observer
“组件协作”模式: #现代软件专业分工之后的第一个结果是“框架与应用程序的划分”,“组件协作”模式通过晚期绑定,来实现框架与应用程序之间的松耦合,是二者之间协作时常用的模式. #典型模式: Templ ...
- mysql主备部署[高可用]
配置方案 master:192.168.99.61 service-id:61 slave:192.168.99.62 service-id:62同步账号:sync 同步密码:sync 主:192 ...
- ubuntu服务器安装FTP服务
目录 ubuntu服务器安装FTP服务 一.实验环境 二.安装配置FTP 下载ftp 配置环境 新建用户 ubuntu服务器安装FTP服务 参考教程 [ubuntu16.04搭建ftp服务器 一.实验 ...
- 20165211 2017-2018-2 《Java程序设计》第6周学习总结
20165211 2017-2018-2 <Java程序设计>第6周学习总结 教材学习内容总结 本周,我学习了书本上第八.十五两章的内容,以下是我整理的主要知识. 第八章 常用实用类 St ...
- __NSCFConstantString && __NSPlaceholderDictionary
一 -[__NSCFConstantString size]: unrecognized selector sent to instance 0x53ea70 该错误是在我将NSString类型的参数 ...