Crime and Punishment
来源:互联网 发布:淘宝怎么申请ifashion 编辑:程序博客网 时间:2024/06/01 10:20
链接:http://acm.timus.ru/problem.aspx?space=1&num=1430
题目:
题解:
题目:
Background
Petty bureaucrat Victor Thiefton was disposed towards stealing from his childhood. But one thing is to legally privatize national factories, diamond fields and oil derricks at the cost of billions dollars. And another thing is to filch some money from a poor regional budget. Our legislation is very strict. Therefore Victor felt that justice is on the alert just after he extracted his hand from the national pocket. What should he do to escape inevitable punishment?
Mr. Thiefton has once heard that in accordance with the criminal legislation standards he would be condemned to long imprisonment for a theft whereas in case of a peculation he could escape with a suspended sentence only. So if the most part of stolen money is peculated, the duration of imprisonment will be reduced.
Problem
The same evening Mr. Thiefton burst into "MegaApril" superstore and rushed for overflowing storefronts carrying a purse with N stolen dollars. It appeared that unlimited number of high-quality goods and goods at moderate price were on sale in the superstore. High-quality goods cost A dollars per piece, and goods at moderate price cost B dollars per piece. Victor should spend as much stolen money as possible to reduce the duration of imprisonment to a minimum.
题意:数字abc,求n*a+m*b最大且n*a+m*b<=c的n和m(任意)
分析:数论内容(最大公约数最小公倍数),也可暴力求解题解:
#include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <queue>#include <stack>#include <vector>#include <map>#include <string>#include <cstring>#include <functional>#include <cmath>#include <cctype>#include <cfloat>#include <climits>#include <complex>#include <deque>#include <list>#include <set>#include <utility>using namespace std;int gcd(int a,int b){return (b)?gcd(b,a%b):a;}int main(){int a,b,n,g,t,res,x,y;scanf("%d %d %d",&a,&b,&n);bool flag=false;if(a<b){swap(a,b);flag=true;}g=gcd(a,b);n/=g;a/=g;b/=g;t=n/a;res=n;x=y=0;for(int i=0;i<=t;++i){if(res>(n-i*a)%b){x=i;y=(n-i*a)/b;res=n-x*a-y*b;if(res==0)break;}}if(flag)printf("%d %d\n",y,x);elseprintf("%d %d\n",x,y);return 0;}
0 0
- Crime and Punishment
- 1.4 Crime and Punishment
- Ural 1430. Crime and Punishment
- Ural 1430. Crime and Punishment(数论)
- Crime
- Commit-and- Run Is a Crime
- Is punishment necessary to help children learn the difference between right and wrong?
- Cyber Crime Investigations: Bridging the Gaps Between Security Professionals, Law Enforcement, and P
- Endless Punishment——HOJ
- A breach beyond CRIME
- Acdream 1729 Crime
- Kaggle 入门 Crime
- zoj 1792 Gap Punishment Aligment Problem
- HDU 4887 Endless Punishment (矩阵离散对数)
- [HDU 4887 Endless Punishment] 矩阵离散对数
- UVa10746 Crime Wave - The Sequel
- San Francisco Crime Classification(Kaggle)
- uva 10746 - Crime Wave - The Sequel
- 动态规划
- 搭个外网可访问的TOMCAT、SVN
- Learning Spark 笔记(二) -- aggregate初值初探
- 动态加载未安装的apk文件里面的类
- Android4.2使用TextClock出现"HH:00"的问题的解决方案
- Crime and Punishment
- 怎样在知网检索SCI/EI期刊
- Docker网络优化方案,你认为哪种将引爆未来?
- OpenCV 系列 --- 形态学操作(膨胀、腐蚀)
- 进程之间的通信
- QT5 creator 调试器未配置
- 树莓派学习笔记—— 源代码方式安装opencv
- Thinkpad T550 安装Ubuntu16.04 配置 Shadowsocks 安装fcitx五笔98词库
- Git的安装配置