zoukankan      html  css  js  c++  java
  • Codeforces Round #281 (Div. 2) B. Vasya and Wrestling 水题

    B. Vasya and Wrestling

    题目连接:

    http://codeforces.com/contest/493/problem/B

    Description

    Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.

    When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins.

    If the sequences of the awarded points coincide, the wrestler who performed the last technique wins. Your task is to determine which wrestler won.

    Input

    The first line contains number n — the number of techniques that the wrestlers have used (1 ≤ n ≤ 2·105).

    The following n lines contain integer numbers ai (|ai| ≤ 109, ai ≠ 0). If ai is positive, that means that the first wrestler performed the technique that was awarded with ai points. And if ai is negative, that means that the second wrestler performed the technique that was awarded with ( - ai) points.

    The techniques are given in chronological order.

    Output

    If the first wrestler wins, print string "first", otherwise print "second"

    Sample Input

    5
    1
    2
    -3
    -4
    3

    Sample Output

    second

    Hint

    题意

    有n个分数,然后输入,如果是正数,那么就属于第一个人,如果是负数,那么就属于第二个人。

    谁分数大,谁胜利。

    如果分数一样,那么看字典序大小。

    如果字典序大小一样,看最后的那个数属于谁

    题解:

    读题比做题难……

    模拟一下就好了

    代码

    #include<bits/stdc++.h>
    using namespace std;
    
    vector<int> a,b;
    int judge()
    {
        for(int i=0;i<a.size()&&i<b.size();i++)
        {
            if(a[i]>b[i])return 1;
            if(b[i]>a[i])return 2;
        }
        return 0;
    }
    int main()
    {
        int n;
        long long sum1=0,sum2=0;
        scanf("%d",&n);
        int flag = 0;
        for(int i=0;i<n;i++)
        {
            int x;scanf("%d",&x);
            if(x>0)
            {
                a.push_back(x);
                sum1+=x;
                flag = 1;
            }
            else
            {
                b.push_back(-x);
                sum2+=-x;
                flag = 2;
            }
        }
        if(sum1>sum2)return puts("first"),0;
        if(sum2>sum1)return puts("second"),0;
        if(judge()==1)return puts("first"),0;
        else if(judge()==2)return puts("second"),0;
        if(flag==1)return puts("first"),0;
        else return puts("second"),0;
    }
  • 相关阅读:
    ActionScript 条件编译
    FLASH通讯小结
    关于ob_start()
    剖析PHP中的输出缓冲
    Ext.app.controller的refs
    php多线程解决之stream_socket_client
    谷歌的JQuery库
    PHP计划任务之关闭浏览器后仍然继续执行的函数
    关于php调用可执行程序,在后台运行而不让页面等待
    把预定义的字符串转化为html标签
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5844245.html
Copyright © 2011-2022 走看看