Google Code Jam 2010 Round 1C Problem A. Rope Intranet
https://code.google.com/codejam/contest/619102/dashboard#s=p0

Problem A. Rope Intranet

A company is located in two very tall buildings. The company intranet connecting the buildings consists of many wires, each connecting a window on the first building to a window on the second building.

You are looking at those buildings from the side, so that one of the buildings is to the left and one is to the right. The windows on the left building are seen as points on its right wall, and the windows on the right building are seen as points on its left wall. Wires are straight segments connecting a window on the left building to a window on the right building.

You've noticed that no two wires share an endpoint (in other words, there's at most one wire going out of each window). However, from your viewpoint, some of the wires intersect midway. You've also noticed that exactly two wires meet at each intersection point.

On the above picture, the intersection points are the black circles, while the windows are the white circles.

How many intersection points do you see?

Input

The first line of the input gives the number of test cases, TT test cases follow. Each case begins with a line containing an integer N, denoting the number of wires you see.

The next N lines each describe one wire with two integers Ai and Bi. These describe the windows that this wire connects: Ai is the height of the window on the left building, and Biis the height of the window on the right building.

Output

For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1) and y is the number of intersection points you see.

Limits

1 ≤ T ≤ 15.
1 ≤ Ai ≤ 104.
1 ≤ Bi ≤ 104.
Within each test case, all Ai are different.
Within each test case, all Bi are different.
No three wires intersect at the same point.

Small dataset

1 ≤ N ≤ 2.

Large dataset

1 ≤ N ≤ 1000.

Sample

Input 
 
Output 
 
2
3
1 10
5 5
7 7
2
1 1
2 2
Case #1: 2
Case #2: 0

 

Solution:

vector<int> linesL;
vector<int> linesR; int solve()
{
int L1, R1, L2, R2, is = ;
int count = (int)linesL.size();
for (int i = ; i < count; i++) {
L1 = linesL[i]; R1 = linesR[i];
for (int j = i; j < count; j++) {
L2 = linesL[j]; R2 = linesR[j]; if ((L1 < L2 && R1 > R2) || (L1 > L2 && R1 < R2)) {
is++;
}
}
} return is;
} int main()
{
freopen("in.in", "r", stdin);
freopen("out.out", "w", stdout); int T;
scanf("%d\n", &T);
if (!T) {
cerr << "Check input!" << endl;
exit();
} for (int t = ; t <= T; t++) {
cerr << "solving: #" << t << " / " << T << endl; linesL.clear();
linesR.clear(); int lc;
scanf("%d\n", &lc); for (int l = ; l < lc; l++) {
int lL, lR;
scanf("%d %d\n", &lL, &lR);
linesL.push_back(lL);
linesR.push_back(lR);
} auto result = solve();
printf("Case #%d: %d\n", t, result);
} fclose(stdin);
fclose(stdout);
return ;
}

Google Code Jam 2010 Round 1C Problem A. Rope Intranet的更多相关文章

  1. Google Code Jam 2010 Round 1C Problem B. Load Testing

    https://code.google.com/codejam/contest/619102/dashboard#s=p1&a=1 Problem Now that you have won ...

  2. Google Code Jam 2010 Round 1A Problem A. Rotate

    https://code.google.com/codejam/contest/544101/dashboard#s=p0     Problem In the exciting game of Jo ...

  3. Google Code Jam 2010 Round 1B Problem B. Picking Up Chicks

    https://code.google.com/codejam/contest/635101/dashboard#s=p1   Problem A flock of chickens are runn ...

  4. Google Code Jam 2010 Round 1B Problem A. File Fix-it

    https://code.google.com/codejam/contest/635101/dashboard#s=p0   Problem On Unix computers, data is s ...

  5. dp - Google Code jam Qualification Round 2015 --- Problem B. Infinite House of Pancakes

    Problem B. Infinite House of Pancakes Problem's Link:   https://code.google.com/codejam/contest/6224 ...

  6. Google Code jam Qualification Round 2015 --- Problem A. Standing Ovation

    Problem A. Standing Ovation Problem's Link:   https://code.google.com/codejam/contest/6224486/dashbo ...

  7. Google Code Jam 2016 Round 1B Problem C. Technobabble

    题目链接:https://code.google.com/codejam/contest/11254486/dashboard#s=p2 大意是教授的学生每个人在纸条上写一个自己的topic,每个to ...

  8. Google Code Jam 2009, Round 1C C. Bribe the Prisoners (记忆化dp)

    Problem In a kingdom there are prison cells (numbered 1 to P) built to form a straight line segment. ...

  9. Google Code Jam 2016 Round 1C C

    题意:三种物品分别有a b c个(a<=b<=c),现在每种物品各选一个进行组合.要求每种最和最多出现一次.且要求任意两个物品的组合在所有三个物品组合中的出现总次数不能超过n. 要求给出一 ...

随机推荐

  1. python设计模式之装饰器详解(三)

    python的装饰器使用是python语言一个非常重要的部分,装饰器是程序设计模式中装饰模式的具体化,python提供了特殊的语法糖可以非常方便的实现装饰模式. 系列文章 python设计模式之单例模 ...

  2. 64_o1

    OCE-devel-0.18.1-1.fc26.i686.rpm 15-May-2017 18:37 5634474 OCE-devel-0.18.1-1.fc26.x86_64.rpm 15-May ...

  3. HTTP 请求 的方法Util

    HTTP请求 的一系列方法总结 /** * *******************************传统请求--开始************************************** ...

  4. EasyUi – 5.修改$.messager.show() 弹出窗口在浏览器顶部中间出现

    由于在easyui中$.messager.show() 只有一种弹出方式(在浏览器的或下角弹出),我最近在做一个项目的时候需要在浏览器的顶部中间出现.由于自己写花那么多的时间,所以就去修改了原码(不推 ...

  5. apache Apache winnt_accept: Asynchronous AcceptEx failed 错误的解决

    httpd配置文件中添加: AcceptFilter http noneAcceptFilter https none apache优化: http://blog.csdn.net/hytfly/ar ...

  6. python脚本传入参数--精讲(getopt模块)

    1.最常用的sys.argv[],这个不多谈 2.形如 dahu@dahu-OptiPlex-:~/json_folder$ python sub1.py -abb -oaaa --output=ou ...

  7. SQL 如何查找一个表里,每个班级各个学科的最高分?

    SQL 如何查找一个表里,每个班级各个学科的最高分? 学生表:STUDENT(S#,SNAME,SAGE,SSEX,CLASSNO) 班级表:CLASS(CLASSNO,CLASSNAME) 课程表: ...

  8. sublime text3 如何在多行前面快速插入序号

    sublime text3 如何在多行前面快速插入序号 1.需要安装InsertNums插件 首选项 -> Package Control -> Install Package -> ...

  9. Xcode10升级项目报错library not found for -lstdc++.6.0.9

    在升级Xcode10后运行项目会发出报了一个错“library not found for -libstdc++.6.0.9”,很简单,就是因为xocde10后这个libstd++.6.0.9库已经不 ...

  10. 【WPF】奇怪的INotifyPropertyChanged的实现

    MSDN是这样解释的: INotifyPropertyChanged 接口用于向客户端(通常是执行绑定的客户端)发出某一属性值已更改的通知. 例如,考虑一个带有名为 FirstName 属性的 Per ...