H-Greed
crawling in process ... crawling failed time limit:3000MS Memory Limit:0KB 64bit IO for Mat:%lld &%llu
Submit Status
Description
Most financial institutions had become insolvent during financial crisis and went bankrupt or were bought by larger Instit Utions, usually by banks. By the end of financial crisis of all the financial institutions only a banks still continue to operate. Financial had remained closed throughout the crisis and now regulators is gradually opening them. To prevent speculation and to gradually ramp up trading they would initially allow trading on only one financial instrument and the volume of trading is limited to
I<tex2html_verbatim_mark> Contracts for
I<tex2html_verbatim_mark>-th minute of the market operation. Banks had decided to cooperate and the Government to kick-start the market operation. The boards of directors had agreed on trading volume for each minute of this first trading session. One bank would be buying
aI<tex2html_verbatim_mark> Contracts ( 1
aI
I<tex2html_verbatim_mark>) during
I<tex2html_verbatim_mark>-th Minute ( 1
I
N<tex2html_verbatim_mark>) While the other one would be selling. They don't really care whether to buy or to sell, and the outside observer would only see the volume
a i<tex2html_verbatim_mark> of contracts traded per minute. However, they do not want to take any extra risk and want to has no position in the contract by the end of the trading SE Ssion. Thus, if we define
b i = 1<tex2html_verbatim_mark> when the first bank is buying and
b i =-1<tex2html_verbatim_mark> when the second one are buying (and the first one is selling ), then the requirement for the trading session was that!--MATH $\sum_{i=1}^{n}a_i b_i = 0$--> a i
b i = 0<tex2html_verbatim_mark>. Your Lucky team of three still works in the data center (due to the crisis, banks now share the data center and its person Nel) and your task is to find such
b i<tex2html_verbatim_mark> Impossible. input < Span class= "math" > the input file contains several test cases, each of them as described below. The first line of the input contains the single integer number
n <tex2html_verbatim_mark> ; (!--math $ \le n \le 100\,000$-->1
n 100&NBSP;000<TEX2HTML_VERBATIM_MARK&G T ). The second line of the input contains
n <tex2html_verbatim_mark> integer Numbers--
a i<tex2html_verbatim_mark> (!--math $ \le a_i \le i$--> 1
a i
i <tex2html_verbatim_mark>). Outputfor each test case, the first line of the output must contain " Yes" if the trading session with Specifie D volumes is possible and ' No' otherwise. In the former option a second line must contain
n<tex2html_verbatim_mark> Numbers--
Bi<tex2html_verbatim_mark>. Sample Input
41 2 3 341 2 3 4
Sample Output
Noyes1-1-1 1
Problem Solving Ideas:
The idea of this topic is to enter n number, to determine whether the N number can be divided into the sum of half and equal, we can define a class or structure array storage, and define two member x,y,x to hold the input number, Y is used to record the position of this number, because then we have to
X to sort, and then define an array of shaping, to record the number of times-1 or 1, and finally to control the loop condition, when all the number of the and is odd, the direct output of no, or the number of 1 also directly output no, otherwise output Yes, and output scheme, that is, b array
Program code:
#include <cstdio>#include<algorithm>using namespacestd;Const intmax=100010;Long Longsum;intn,i;intB[max];structnode{intx, y;} A[max];BOOLCMP (node A,node b) {returnA.x>b.x;}BOOLinit () {sum=0; for(intI=0; i<n;i++) {scanf ("%d",&a[i].x); A[i].y=i; B[i]=-1; Sum+=a[i].x; } if(sum%2)return true; Else return false;}voidsolve () {sort (a,a+n,cmp); Long Longnum=0; for(i=0; i<n;i++) { if(num+a[i].x<=sum/2) {num+=a[i].x; B[A[I].Y]=1; if(num==sum/2) Break; } }}voidprint () { for(i=0; i<n-1; i++) {printf ("%d", B[i]); } printf ("%d\n", b[n-1]);}intMain () { while(SCANF ("%d", &n) = =1) { if(init () | | | n==1) printf ("no\n"); Else{printf ("yes\n"); Solve (); Print (); } } return 0;}View Code
---restore content ends---
Most financial institutions greedy H