1430. Crime and Punishment
生活随笔
收集整理的這篇文章主要介紹了
1430. Crime and Punishment
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
http://acm.timus.ru/problem.aspx?space=1&num=1430
先讓 a 變成較大的那個
1,a 的個數 不會超過 n/a
2,a 的個數也可以不超過 b ,如果超過 b個a 可以由 a個b 代替 從而減輕了 a 的個數過大的負擔
然后枚舉 a 的個數
因為 a 變成較大的那個 所以? min(n/a,b)? 比較小
代碼:
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<string> #include<vector> #include<map> #include<queue> #include<stack> #include<cmath> #define LL long long //#pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std;const int INF=0x3f3f3f3f;int main() {//freopen("data.txt","r",stdin);LL a,b,n;while(cin>>a>>b>>n){bool change=false;if(a<b){change=true;swap(a,b);}LL k1,k2,MAX=-1;for(LL i=0;i<=min(n/a,b);++i){LL j=(n-i*a)/b;if(i*a+j*b>MAX){MAX=i*a+j*b;k1=i;k2=j;}}if(change)swap(k1,k2);cout<<k1<<" "<<k2<<endl;}return 0; }?
轉載于:https://www.cnblogs.com/liulangye/archive/2012/10/25/2740072.html
總結
以上是生活随笔為你收集整理的1430. Crime and Punishment的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python:50行代码实现下载小说,图
- 下一篇: html布尔属性写法,HTML - 为