CodeForces 681B
来源:互联网 发布:奇葩校规知乎 编辑:程序博客网 时间:2024/06/11 01:33
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=121183#problem/G
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
1359257
YES
17851817
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循环一遍一定超时
- CodeForces 681B
- CodeForces 681B
- CodeForces 681B Economy Game
- CodeForces - 681B Economy Game
- CodeForces-681B.Economy Game
- CodeForces 681B Economy Game
- codeforces B
- codeforces B
- codeforces B
- codeforces B
- CodeForces 681B Economy Game (暴力)
- 【codeforces 681B】【优化循环】Economy Game
- CodeForces 626B CodeForces 626B【暴力】
- CodeForces 841B (B) 博弈
- codeforces 134B
- codeforces#98 b
- codeforces 105 div2 B
- Codeforces 166B - Polygons
- 项目管理过程
- Eclipse启动Tomcat时45秒超时解决方法
- nginx-服务器多虚拟主机配置
- 三门问题 概率论
- Java并发之 volatile关键字解析
- CodeForces 681B
- 文章标题
- Android开发---动态设置控件颜色
- opencv介绍
- ViewPager轮播图:自动无限轮播,手指长按停止,实现点击事件(实用版)
- 剑指offer43--字符串转化成整数
- LockSupport源码探索
- 第五章 C++的内存模型和原子操作
- Minor GC、Major GC和Full GC之间的区别