UESTC_Tournament CDOJ 124

时间:2022-09-25 20:36:49

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×(N−1)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+Ei≥Sj and Sj+Ej≥Si. CD equals to the number of competitive matches among all N×(N−1)2 matches in the tournament.

Input

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

Output

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

Sample input and output

Sample Input Sample 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+Ei≥Sj and Sj+Ej≥Si
第一想法是暴力,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 + ;
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 = ;
scanf("%d",&n);
for(int i = ; i < n ; ++ i)
scanf("%d%d",&A[i].s,&A[i].e);
sort(A,A+n);
s.clear();
s.insert(A[].s);
set<int>::iterator it = s.begin();
int cot = ;
for(int i = ; i < n ; ++ i)
{
int temp = A[i].s + A[i].e;
while( s.size() > && *it > temp)
{
s.erase(it--);
cot--;
}
ans += cot++;
s.insert(A[i].s);
if (A[i].s >= *it)
it++;
}
cout << ans << endl;
}
return ;
}

UESTC_Tournament CDOJ 124的更多相关文章

  1. cdoj 1489 老司机采花

    地址:http://acm.uestc.edu.cn/#/problem/show/1489 题目: 老司机采花 Time Limit: 3000/1000MS (Java/Others)     M ...

  2. NYOJ题目124中位数

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAssAAAJUCAIAAABsWvwaAAAgAElEQVR4nO3dPXLjuraG4TsJ5xqIYw

  3. Error -27780&colon; &lbrack;GENERAL&lowbar;MSG&lowbar;CAT&lowbar;SSL&lowbar;ERROR&rsqb;connect to host &quot&semi;124&period;202&period;213&period;70&quot&semi; failed&colon; &lbrack;10054&rsqb; Connection reset by peer &lbrack;MsgId&colon; MERR-27780&rsqb;

    解决方案一: 备注: 此方案如果请求响应时间太长,勾选"WinInet replay instead of Sockets(Windows only)"将会导致如下错误:

  4. TypeError&colon; argument to reversed&lpar;&rpar; must be a sequence ERROR basehttp 124 &quot&semi;GET &sol;admin&sol; HTTP&sol;1&period;1&quot&semi; 500 114103 Performing system checks&period;&period;&period;

    Error Msg TypeError: argument to reversed() must be a sequence ERROR basehttp 124 "GET /admin/ ...

  5. leetcode 124&period; Binary Tree Maximum Path Sum 、543&period; Diameter of Binary Tree&lpar;直径&rpar;

    124. Binary Tree Maximum Path Sum https://www.cnblogs.com/grandyang/p/4280120.html 如果你要计算加上当前节点的最大pa ...

  6. SGU 124&period; Broken line 射线法 eps的精准运用&comma;计算几何 难度&colon;3

    124. Broken line time limit per test: 0.25 sec. memory limit per test: 4096 KB There is a closed bro ...

  7. 编写高质量代码改善C&num;程序的157个建议——建议124:考虑在命名空间中使用复数

    建议124:考虑在命名空间中使用复数 如果有一组功能相近的类型被分到了同一个命名空间想,可以考虑为命名空间使用复数. 最典型的例子有,在FCL中,我们需要把所有的非泛型集合类集中在一起存放,所以就有了 ...

  8. Loj &num;124&period; 除数函数求和

    链接:https://loj.ac/problem/124 就是筛一下积性函数. #include<bits/stdc++.h> #define ll long long #define ...

  9. CDOJ 1324 卿学姐与公主(分块)

    CDOJ 1324 卿学姐与公主(分块) 传送门: UESTC Online Judgehttp://acm.uestc.edu.cn/#/problem/show/1324 某日,百无聊赖的卿学姐打 ...

随机推荐

  1. Python之路-&lpar;Django进阶一)

    Django请求生命周期: 首先,客户端发送请求到服务器的urls库,通过匹配url后面的关键字,去找指定app里面的的view. 然后,app通过判断,拿到数据库数据和html模板文件. 最后,将拿 ...

  2. docker数据拷贝

    docker数据拷贝的方式有很多种,下面介绍几种数据拷贝的方式:此处只是介绍几种简易的方式,更多方式可以google下. 从容器中向主机拷贝数据 docker cp <containerId&g ...

  3. &lbrack;原创&rsqb;cocos2d-x研习录-第一阶 背景介绍 之 cocos2d家族史

    Cocos2D是一个2D开源游戏引擎,它最早是由Ricardo Quesada(阿根廷人,社区简称Riq)和他的朋友们用Python开发的,用于开发2D游戏和基于2D图形的任何应用.最早引擎的名字源自 ...

  4. Matlab编程实例&lpar;1&rpar; 移动平均

    MATLAB数字信号处理作业,把自己写的程序发上来..欢迎交流~ QQ 五幺九七九零*   首先是任意点移动平均: 主程序:mov_average_main.m (运行) 函数:mov_averag ...

  5. Vue中method与computed的区别

    为了说明method与computed的区别,在此我想先来看看computed属性在vue官网中的说法:模板内的表达式是非常便利的,但是它们实际上只用于简单的运算.在模板中放入太多的逻辑会让模板过重且 ...

  6. Java基础(变量数&amp&semi;常量&amp&semi;据类型&amp&semi;类型转换)

    什么是变量: 变量就是一个不固定的数值,它随时会改变,就像银行卡里存的钱一样会变动. 变量的格式:1  数据类型 变量名=变量值:  2  数据类型 变量名: 变量名=变量值: 变量的三大要素:1变量 ...

  7. centos6&period;5修改yum安装的mysql默认目录

    0.说明 Linux下更改yum默认安装的mysql路径datadir. linux下,MySQL默认的数据文档存储目录为/var/lib/mysql. 假如要把MySQL目录移到/home/data ...

  8. 从一条巨慢SQL看基于Oracle的SQL优化&lpar;重磅彩蛋&plus;PPT&rpar;

    本文根据DBAplus社群第110期线上分享整理而成,文末还有好书送哦~ 讲师介绍 丁俊 新炬网络首席性能优化专家 SQL审核产品经理 DBAplus社群联合发起人.<剑破冰山-Oracle开发 ...

  9. MFC命名规范

    属性部分 全局变量:g_ 常量:c_ c++类成员变量:m_ 静态变量:s_ 类型部分 指针:p 函数:fn 无效:v 句柄:h 长整型:l 布尔:b 浮点型(有时也指文件):f 双字:dw 字符串: ...

  10. js获取textaera对象(object)的值

    for(i in pstrWord ){ alert(i); //获得属性 alert(pstrWord[i]); //获得属性值 } 1.js输出object对象方法如下: function wri ...