Crime and Punishment

原创 2016年08月28日 17:44:05
链接: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);
	else
		printf("%d %d\n",x,y);
	return 0;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

Commit-and- Run Is a Crime

Commit-and- Run Is a CrimeNiclas NilssoniT’S lATE in THE AFTERnoon. The team is churning out the la...

IT helps in crime fighting

  • 2014-03-28 21:08
  • 2.83MB
  • 下载

UVA 10746 Crime Wave - The Sequel

这个题目真是无力吐槽,WA了几次之后去uva论坛一看原来是精度问题,对比了别人的测试数据发现因为某一个输出 总是比别人的小0.01,最短路判断改成这样:if(p->c && dis[j = p->i]...

Acdream 1729 Crime

Crime Time Limit: 2000/1000MS (Java/Others) Memory Limit: 262144/131072KB (Java/Others) Submit Sta...

C++Crime中文版(第3版)

  • 2017-07-25 10:13
  • 4.67MB
  • 下载

UVa 10746 Crime Wave - The Sequel (最小费用最大流+卡精度)

题意:还记得上次那些抢银行的强盗吗?这次为了银行的安全,要派一些警察去守护这些银行。现在有n个银行和m警察,给出每个警察到达各个银行的时间,问说怎么样安排人手,可以使的警察到达银行的平均时间最小。 ...

Kaggle 入门 Crime

对犯罪案件进行分类 提交每个类别概率 xgboost成绩 2.35461feature: Category用preprocessing.labelEncoder()转成int型有序变量 ...

UVA 10746 Crime Wave – The Sequel(费用流)

题意: 有m个警察,派n个警察到n个银行,给出每个警察到各银行的时间,求最小的平均时间。 分析: 平均乘上n就是总时间,也就是要最小化总时间,那么用费用流就可以解决问题。各银行向每个警察连边,容量1,...

UVa10746 Crime Wave - The Sequel

题意:n个银行,m个警察,(n<=m)
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)