CF 421D--Bug in code
2014-04-24 19:14
381 查看
Recently a serious bug has been found in the FOS code. The head of the F company wants to find the culprit and punish him. For that, he set up an organizational meeting, the issue is: who's bugged the code? Each of the n coders
on the meeting said: 'I know for sure that either x or y did
it!'
The head of the company decided to choose two suspects and invite them to his office. Naturally, he should consider the coders' opinions. That's why the head wants to make such a choice that at least p of n coders
agreed with it. A coder agrees with the choice of two suspects if at least one of the two people that he named at the meeting was chosen as a suspect. In how many ways can the head of F choose two suspects?
Note that even if some coder was chosen as a suspect, he can agree with the head's choice if he named the other chosen coder at the meeting.
Input
The first line contains integers n and p (3 ≤ n ≤ 3·105; 0 ≤ p ≤ n) —
the number of coders in the F company and the minimum number of agreed people.
Each of the next n lines contains two integers xi, yi (1 ≤ xi, yi ≤ n) —
the numbers of coders named by the i-th coder. It is guaranteed that xi ≠ i, yi ≠ i, xi ≠ yi.
Output
Print a single integer — the number of possible two-suspect sets. Note that the order of the suspects doesn't matter, that is, sets (1, 2)and (2, 1) are
considered identical.
Sample test(s)
input
output
input
output
题意:每个人怀疑2个人。一个方案视为可能方案当且仅当有超过P个人支持这个方案。I支持方案J当且仅当J中至少有一个是I所怀疑的
思路:将每个人按做嫌疑犯的支持人数排序。然后扫描,比如当前位置是x,支持人数是y.在x+1与n之间二分找到支持人数>=p-y的第一个。每一个都这么处理。最后再减去重复的情况。比如有2个人都是(3,5)。那按照我前面的做法这个集合支持度是4.但实际是2、也就是要减去重复的、、、只需将原来每个人按写的2个号码第一从小到大,第二个从小到大排序、、如果有(x,y)出现了z次,且zhichi[x]+zhichi[y]>=p && zhichi[x]+zhichi[y]-z < p那么ans--;
on the meeting said: 'I know for sure that either x or y did
it!'
The head of the company decided to choose two suspects and invite them to his office. Naturally, he should consider the coders' opinions. That's why the head wants to make such a choice that at least p of n coders
agreed with it. A coder agrees with the choice of two suspects if at least one of the two people that he named at the meeting was chosen as a suspect. In how many ways can the head of F choose two suspects?
Note that even if some coder was chosen as a suspect, he can agree with the head's choice if he named the other chosen coder at the meeting.
Input
The first line contains integers n and p (3 ≤ n ≤ 3·105; 0 ≤ p ≤ n) —
the number of coders in the F company and the minimum number of agreed people.
Each of the next n lines contains two integers xi, yi (1 ≤ xi, yi ≤ n) —
the numbers of coders named by the i-th coder. It is guaranteed that xi ≠ i, yi ≠ i, xi ≠ yi.
Output
Print a single integer — the number of possible two-suspect sets. Note that the order of the suspects doesn't matter, that is, sets (1, 2)and (2, 1) are
considered identical.
Sample test(s)
input
4 2 2 3 1 4 1 4 2 1
output
6
input
8 65 65 7
5 8
6 2
2 1
7 3
1 3
1 4
output
1
题意:每个人怀疑2个人。一个方案视为可能方案当且仅当有超过P个人支持这个方案。I支持方案J当且仅当J中至少有一个是I所怀疑的
思路:将每个人按做嫌疑犯的支持人数排序。然后扫描,比如当前位置是x,支持人数是y.在x+1与n之间二分找到支持人数>=p-y的第一个。每一个都这么处理。最后再减去重复的情况。比如有2个人都是(3,5)。那按照我前面的做法这个集合支持度是4.但实际是2、也就是要减去重复的、、、只需将原来每个人按写的2个号码第一从小到大,第二个从小到大排序、、如果有(x,y)出现了z次,且zhichi[x]+zhichi[y]>=p && zhichi[x]+zhichi[y]-z < p那么ans--;
相关文章推荐
- Codeforces 421D Bug in Code(思维)
- codeforces 421d bug in code
- Coder-Strike 2014 - Finals (online edition, Div. 1) C. Bug in Code
- cf Educational Codeforces Round 6 C Pearls in a Row
- Coder-Strike 2014 - Finals (online edition, Div. 2)——Bug in Code
- codeforces 420C. Bug in Code
- codeforce 421D D. Bug in Code
- 【Codeforces】【Coder-Strike 2014 - Finals】【D Bug in Code】
- Discuz7.2 BUG :"Warning: sprintf() [function.sprintf]: Too few arguments in xxxxxxxx/include/discuzcode.func.php on line 369"
- Codeforces 420 C. Bug in Code
- Bug in Code
- Coder-Strike 2014 - Finals (online edition, Div. 2) D.Bug in Code
- CodeSign error: code signing is required for product type Application in SDK iOS
- Install Visual Studio Code in Ubuntu 16.04 LTS
- populating-next-right-pointers-in-each-node Java code
- Code Reuse in Google Chrome Browser
- In Java, will the code in the finally block be called and run after a return statement is executed?
- Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE
- C# Code in ASPX Page
- warning C4819: The file contains a character that cannot be represented in the current code page