CodeForces 681B
2016-07-10 11:19
495 查看
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=121183#problem/G
G - Economy Game
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d
& %I64u
Submit Status Practice CodeForces
681B
Description
Kolya is developing an economy simulator game. His most favourite part of the development process is in-game testing. Once he was entertained by the testing so much, that he found out his game-coin score become equal to 0.
Kolya remembers that at the beginning of the game his game-coin score was equal to n and that he have bought only some houses (for 1 234 567 game-coins
each), cars (for 123 456 game-coins each) and computers (for 1 234 game-coins each).
Kolya is now interested, whether he could have spent all of his initial n game-coins buying only houses, cars and computers or there is a bug in the game. Formally, is there a triple of non-negative
integers a, b and c such that a × 1 234 567 + b × 123 456 + c × 1 234 = n?
Please help Kolya answer this question.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 109) — Kolya's initial game-coin
score.
Output
Print "YES" (without quotes) if it's possible that Kolya spent all of his initial n coins buying only houses, cars and computers. Otherwise print "NO"
(without quotes).
Sample Input
Input
Output
Input
Output
题意:给出一个游戏币数求买买房车电脑能不能恰好花完
不思考的暴力 超时
一个技巧减少一层循环
G - Economy Game
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d
& %I64u
Submit Status Practice CodeForces
681B
Description
Kolya is developing an economy simulator game. His most favourite part of the development process is in-game testing. Once he was entertained by the testing so much, that he found out his game-coin score become equal to 0.
Kolya remembers that at the beginning of the game his game-coin score was equal to n and that he have bought only some houses (for 1 234 567 game-coins
each), cars (for 123 456 game-coins each) and computers (for 1 234 game-coins each).
Kolya is now interested, whether he could have spent all of his initial n game-coins buying only houses, cars and computers or there is a bug in the game. Formally, is there a triple of non-negative
integers a, b and c such that a × 1 234 567 + b × 123 456 + c × 1 234 = n?
Please help Kolya answer this question.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 109) — Kolya's initial game-coin
score.
Output
Print "YES" (without quotes) if it's possible that Kolya spent all of his initial n coins buying only houses, cars and computers. Otherwise print "NO"
(without quotes).
Sample Input
Input
1359257
Output
YES
Input
17851817
Output
NO
题意:给出一个游戏币数求买买房车电脑能不能恰好花完
不思考的暴力 超时
一个技巧减少一层循环
#include<iostream> #include<iomanip> #include<cstdio> #include<cstring> #include<string> #include<algorithm> #include<cmath> using namespace std; typedef long long ll; int main(){ ll n; while(cin>>n){ int a=n/1234567; int b=n/123456; int c=n/1234; int flag=0; for(int i=0;i<=a+1;++i){ for(int j=0;j<=b+1;++j){ if(((ll)n-(ll)i*1234567-(ll)j*123456)>=0&&((ll)n-(ll)i*1234567-(ll)j*123456)%1234==0){flag=1;goto aaa;}//@1 } } aaa:; if(!flag)cout<<"NO\n"; else cout<<"YES\n"; } return 0; }@1 如果此处再把c循环一遍一定超时
相关文章推荐
- Java并发之 volatile关键字解析
- 三门问题 概率论
- nginx-服务器多虚拟主机配置
- 小白笔记--------------jsp超链接传值
- 印象云笔记无法连接到服务器解决办法
- 窗口程序完整流程
- Linux shell 之 提取文件名和目录名的一些方法
- Android四大基本组件介绍以及四大组件的生命周期
- idea代码调试debug篇
- H5与其他平台交互框架
- 李洪强iOS开发之OC[015]#pragma mark的使用
- GDB动态库搜索路径
- RPC 工具 --Thrift(二) Thrift 异步模式
- Bulb Switcher
- Android Studio 创建Drawable资源Shape文件
- 习题:codevs 2822 爱在心中 解题报告
- 1.6 贪婪算法
- Java-static关键字详解
- 习题:codevs 2822 爱在心中 解题报告
- Sum of Two Integers