• UESTC_Tournament CDOJ 124


    A sports company is planning to advertise in a tournament. It is a single round-robin tournament, that's to say competitors play with all the others once. The company thinks that the advertising impact is proportional to the so called competitiveness degree(CD) of the tournament.

    CD is calculated in the following way: We assume there're N competitors in the tournament and of course N×(N1)2 matches in total. For each competitor we define two values S and E which stand for skill and experience. We say a match between competitor i and competitor j is competitive if and only if Si+EiSj and Sj+EjSi. CD equals to the number of competitive matches among all N×(N1)2 matches in the tournament.

    Input

    One integer T (T20) on the first line indicates the number of cases. The first line of each case contains one integer N (1N10000) -- the number of competitors. Then N lines follows. The ithline contains two integer Si and Ei (1Si,Ei100000000) which are defined in the description.

    Output

    For each case, print the value of CD on a line.

    Sample input and output

    Sample InputSample Output
    3
    2
    1 2
    4 1
    2
    1 2
    2 2
    5
    1 9
    5 4
    3 4
    2 2
    6 2
    0
    1
    8

    Source

    The 8th UESTC Programming Contest Final
     
    解题报告
    题目意思很简单,找出给出这些整数中有多少队满足
    Si+EiSj and Sj+EjSi
    第一想法是暴力,too simple...结果肯定是TLE
    How to slove?
    我们先对Si + Ei 按照从大到小排序,
    对于排序后的序列来讲,若有i < j,若i能到pos位,则j能到达的位置肯定<=pos
    因此维护一个S单调不减,每次更新答案即可.
    注意到我们不是一次把某队数满足的所有其他队数加上去,而是不断累加(类似于将来的值)
     
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <set>
    
    using namespace std;
    const int maxn = 1e4 + 5;
    int n;
    
    
    multiset<int>s;
    
    typedef struct data
    {
      int s,e;
      friend bool operator < (const data & x,const data & y)
       {
             return x.s + x.e > y.s + y.e;
       }
    };
    
    data A[maxn];
    
    int main(int argc ,char * argv[])
    {
      int Case;
      scanf("%d",&Case);
      while(Case--)
       {
             int ans = 0;
             scanf("%d",&n);
             for(int i = 0 ; i < n ; ++ i)
              scanf("%d%d",&A[i].s,&A[i].e);
             sort(A,A+n);
             s.clear();
             s.insert(A[0].s);
             set<int>::iterator it = s.begin();
             int cot = 1;
             for(int i = 1 ; i < n ; ++ i)
              {
                    int temp = A[i].s + A[i].e;
                    while( s.size() > 0  && *it > temp)
                     {
                           s.erase(it--);
                           cot--;
               }
              ans += cot++;
              s.insert(A[i].s);
              if (A[i].s >= *it)
               it++;
           }
          cout << ans << endl;
       }
      return 0;
    }
    No Pain , No Gain.
  • 相关阅读:
    STM32F407Discovery开发板使用环境搭建
    NIO初识
    Mac下Boost环境搭建
    Android Studio增加NDK代码编译支持--Mac环境
    LNMP平台搭建---PHP安装篇
    LNMP平台搭建---MySQL安装篇
    支付系统流程
    从html字符串中获取div内容---jquery
    记一次进入新公司快速融入开发团队经历
    DataTable复制自身行
  • 原文地址:https://www.cnblogs.com/Xiper/p/4455112.html
Copyright © 2020-2023  润新知