zoj 3407 Doraemon's Cake Machine (思维不能太狭隘了 ,从各个方面考虑问题)
来源:互联网 发布:复杂网络 研究热点 编辑:程序博客网 时间:2024/04/27 22:07
题目链接:http://vjudge.net/problem/viewProblem.action?id=12980
思路:
我们设横切y次,竖切x次,copy z 次;
可以得到方程 x+y+z=m--------(1; (y+1)*2*x+z=n-----(2;(注意x=0的情况)
(2 - (1 2*y*x+x-y+m=n; 明显有 y*x+x-y<=n; 由对称性 我们只需要枚举 1~sqrt(n) 即可得到最小值;
#include <iostream>#include <cstdio>#include <cmath>using namespace std;int main(){ int n,m,t; scanf("%d",&t); while(t--){ scanf("%d%d",&n,&m); if(n<=m){ puts("-1"); continue; } if(n-m==1){ puts("0"); continue; } double temp=sqrt(n*1); int ans=0x7fffffff; for(int x=1;x<=temp;x++){ int y=(n-m-x)/(2*x-1); int z=m-y-x; if(y<0||z<0||2*x*y+2*x+z!=n||ans<z) continue; ans=z; } for(int y=1;y<=temp;y++){ int x=(n-m-y)/(2*y+1); int z=m-x-y; if(x<0||z<0||2*x*y+2*x+z!=n||ans<z) continue; ans=z; } if(ans!=0x7fffffff) printf("%d\n",ans); else puts("-1"); } return 0;}
0 0
- zoj 3407 Doraemon's Cake Machine (思维不能太狭隘了 ,从各个方面考虑问题)
- zoj 3407 Doraemon's Cake Machine
- zoj 3407 Doraemon's Cake Machine
- zoj 3450Doraemon's Railgun
- ZOJ 3450 Doraemon's Railgun
- 思路不能太狭隘,要学他
- (随笔) 是我们眼界太狭隘了
- ZOJ 3452 Doraemon's Stone Game
- ZOJ 3452 Doraemon's Stone Game
- ZOJ 3449:Doraemon's Number Game III
- ZOJ 3449 Doraemon's Number Game III
- ZOJ-3453:Doraemon's Sweet Bullet
- POJ3250从多个方面考虑同一问题
- 从五个方面考虑Oracle的性能调优问题
- ZOJ 3450 Doraemon's Railgun (DP·分组背包)
- ZOJ 3452 Doraemon's Stone Game(高级博弈)
- ZOJ 3452 Doraemon's Stone Game(博弈)
- ZOJ-3447---Doraemon's Number Game (贪心+大数)
- [leetcode] Search in Rotated Sorted Array Python
- GDataXML的使用
- android WIFI直连(未完成)
- freemarker时间格式化
- 聚美陈欧和戴雨森的创业故事
- zoj 3407 Doraemon's Cake Machine (思维不能太狭隘了 ,从各个方面考虑问题)
- 接口程序:HTTP发送报文(HttpURLConnection 发送)
- 模式识别 - 有害视频检测程序的策略
- iOS-RAC实战1-登录
- 同日今天又看
- OpenStack-Heat中的Autoscaling - AWS的autoscaling
- 同桌的你——情书,今夜请不要说话
- 前台外设没有正常工作
- 通过Excel生成DDL语句