Question A: Tong Tong's Trade time limit: 1 Sec memory limit: up to MB
Submitted: Resolution: 2
Submitted State [Discussion Version] Title Description
Tong Tong Home in Allianceance City, friends Robin home in Horde City, Holiday, Robin invited Tong Tong to Horde city tour. The intelligent Tong found that A11iance City and Horde City market some of the goods there is a great difference. Can get a considerable profit from it. In order to earn back the cost of this tour, Tong Tong decided to buy some goods in Alliance City, to Horde city to sell at the local market price, and then buy some goods in Horde city, and then return to Alliance City to sell. Such a back and forth, Tong Tong can earn a lot of money.
Through a business investigation, he had already known the prices of various goods in Alliance City and Horde city before he set out. On the premise of his existing assets, he wants to be able to earn as much gold as possible on a trip. then please design a program for Tong Tong Design a purchase plan, so that a return to make the most gold coins.
Input
Line 1th, two integers n, m (1≤n≤100000;1≤m≤100), indicates that he had N gold coins before departure, and that there were M products in the markets of Allian and horde.
Line 2~m+l, two integers per line ai, Bi, represents the first commodity in the Alliance City market price for AI, in the market price for Bi.
Output
Line 1th, an integer, the maximum number of coins that can be earned in a round trip. The final result is no more than 4000000.
Section 2―m+l, section I+l, the method of purchase of article I, output a sentence. If you want to buy K from Alliance, output "buy K from Alliance", if you want to buy K from Horde, output "buy K from Horde", if you do not need to buy, output "buy 0". If more than one scheme earns the most gold coins, then the output of the purchase of the item number is the most forward of this scenario.
Sample input
23 56 911 73 24 65 3
Sample output
33Buy 3 from Alliancebuy 1 to hordebuy 0Buy 1 from Alliancebuy 9 from Horde
Tips
Initially, Tong Tong in A11iance City, he has 23 gold coins, then he bought 3 goods 1, 1 items 4, spent 3x6+1x4=22 gold coins, the remaining 1 gold coins. When he reached Horde city, he sold them and could get 3x9+1x6=33 gold coins and earn 11 gold coins. At this time, he used his 34 gold coins, in the city of Horde buy 1 goods 2, 9 goods 5, spent lx7+9x3=34 a gold coin. Return to Alliance City, sell can get 1x11+9x5=56 a gold coin, earn 22 gold coins. He earned 33 gold coins compared to his 23 gold coins at the beginning.
It's not correct.
Code:
#include <iostream>#include<cstdio>#include<algorithm>using namespaceStd;typedefstructnode{intA; intb; intc;}; Node no[ $];intcmpintAintb) { returnno[a].b-no[a].a>no[b].b-no[b].a;}intMain () {intN; intm; intL=0; intp=0; intaa[ the]; intshifou_aa[ the]={0}; intbb[ the]; intshifou_bb[ the]={0}; intk=1; intsum1=0; intSum2=0; intsum=0; scanf ("%d%d",&n,&m); for(intI=0; i<m;i++) {scanf ("%d%d",&no[i].a,&no[i].b); if(no[i].a<no[i].b) {NO[I].C=1; }Else{no[i].c=2; } } for(intI=0; i<m;i++){ if(no[i].c==1){ for(intj=0; j<n/no[i].a;j++) {aa[k++]=i; }}} sort (Aa,aa+k-1, CMP); for(intI=1; i<k;i++) {L+=no[aa[i]].a; Shifou_aa[i]=1; if(l<=N) {P=i; }Else{L-=no[aa[i]].a; Shifou_aa[i]=0; Continue; } } for(intI=1; i<=p;i++){ if(shifou_aa[i]==1) {sum1+=no[aa[i]].b-no[aa[i]].a; }} sum=N; N+=sum1; for(intI=0; i<m;i++){ inttemp=no[i].a; NO[I].A=no[i].b; NO[I].B=temp; } ////////////////L=0; for(intI=0; i<m;i++){ if(no[i].c==2){ for(intj=0; j<n/no[i].a;j++) {bb[k++]=i; }}} sort (Aa,aa+k-1, CMP); for(intI=1; i<k;i++) {L+=no[bb[i]].a; Shifou_bb[i]=1; if(l<=N) {P=i; }Else{L-=no[bb[i]].a; Shifou_bb[i]=0; Continue; } } for(intI=1; i<=p;i++){ if(shifou_bb[i]==1) {sum2+=no[bb[i]].b-no[bb[i]].a; } } intsss=sum1+sum2; printf (" %d%d%d", SUM1,SUM2,SSS); return 0;}
View Code
Tong Tong's Trade--wa