• UVA



    Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu

     Status

    Description

    Download as PDF
     
    Most financial institutions had become insolvent during financial crisis and went bankrupt or were bought by larger institutions, usually by banks. By the end of financial crisis of all the financial institutions only two banks still continue to operate. Financial markets had remained closed throughout the crisis and now regulators are gradually opening them. To prevent speculation and to gradually ramp up trading they will initially allow trading in only one financial instrument and the volume of trading will be limited to i<tex2html_verbatim_mark> contracts for i<tex2html_verbatim_mark> -th minute of market operation. Two banks had decided to cooperate with 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 will be buying ai<tex2html_verbatim_mark> contracts ( 1$ le$ai$ le$i<tex2html_verbatim_mark> ) during i<tex2html_verbatim_mark> -th minute ( 1$ le$i$ le$n<tex2html_verbatim_mark> ), while the other one will be selling. They do not really care whether to buy or to sell, and the outside observer will only see the volume ai<tex2html_verbatim_mark> of contracts traded per minute. However, they do not want to take any extra risk and want to have no position in the contract by the end of the trading session. Thus, if we define bi = 1<tex2html_verbatim_mark> when the first bank is buying and bi = - 1<tex2html_verbatim_mark>when the second one is buying (and the first one is selling), then the requirement for the trading session is that $ sum_{{i=1}}^{{n}}$aibi = 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 personnel) and your task is to find such bi<tex2html_verbatim_mark> or to report that this is impossible.

    Input 

    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> ( 1$ le$n$ le$100 000<tex2html_verbatim_mark> ). The second line of the input contains n<tex2html_verbatim_mark> integer numbers -- ai<tex2html_verbatim_mark> ( 1$ le$ai$ le$i<tex2html_verbatim_mark> ).

    Output 

    For each test case, the first line of the output must contain `` Yes'' if the trading session with specified 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 

    4
    1 2 3 3
    4
    1 2 3 4
    

    Sample Output 

    No
    Yes
    1 -1 -1 1
    一组数据,选择其中的一半的数变成负数,加上另一半可以和为0
    输出NO的情况,如果这个数组的和是一个奇数的话,或者只有一个数时,就输出No。
    否则输出Yes,先从大到小排序,从最大的开始加和,加到和大于所有数数和一半的就不能加了,或如果这时刚好和等于所有数和的一半,那么你选择的那个数乘-1。
    #include<iostream>
    #include<algorithm>
    #include<cstdio>
    using namespace std;
    long long sum;
    int t;
    int f[100000000];
    struct node
    {
        int zg;
        int id;
    };
    node a[8000010];
    int cmp(node x,node y)
    {
        return x.zg>y.zg;
    }
    int main()
    {
        while(cin>>t)
        {
            long long sum=0;
            for(int i=0; i<t; i++)
            {
                cin>>a[i].zg;
                a[i].id=i;
                f[i]=-1;
                sum+=a[i].zg;
            }
            if(sum%2||t==1) cout<<"No"<<endl;
            else
            {
                cout<<"Yes"<<endl;
                sort(a,a+t,cmp);
                int s=0;
                for(int i=0; i<t; i++)
                {
                    if(s+a[i].zg<=sum/2)
                    {
                        s+=a[i].zg;
                        f[a[i].id]=1;
                        if(s==sum/2)
                            break;
                    }
                }
                cout<<f[0];
                for(int i=1; i<t; i++)
                {
                    cout<<' '<<f[i];
                }
                cout<<endl;
            }
        }
        return 0;
    }
  • 相关阅读:
    sql注入漏洞详解
    HTTP1.0/1.1/2.0的区别
    http协议详解
    LRU经典算法的原理与实现
    [译转]深入理解LayoutInflater.inflate()
    Touch事件分发机制
    重要:Android绘图只Mask遮罩
    Android View学习Tips
    ViewPager学习及使用(一)
    Android 实现瀑布流的两种思路
  • 原文地址:https://www.cnblogs.com/hfc-xx/p/4709041.html
Copyright © 2020-2023  润新知