题目链接:http://codeforces.com/problemset/problem/421/D

题目大意:每个人说出自己认为的背锅的两个人,最后大BOSS找两个人来背锅,要求至少符合p个人的想法。最终选出的两个人中只有有一个在自己的预测内就算符合想法。

解题思路:统计每个人背锅的次数,排个序。找出相加大于等于p的对数。

然后去重:需要去重的原因,假如有且只有两个人的预测都是 1和2 (其他人的预测不涉及1,、2),则1、2这对组合在我们的计算中符合度为4,实际符合度为2,因此需 要去重

去重过程  x和y分别表示每个人的预测,(x<y),同样的一组预测x和y出现了c次,假如cnt[x]+cnt[y]>=y&&cnt[x]+cnt[y]-c<p,则ans--。

代码如下:

 #include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define FFF 300005
int cnt[FFF],to[FFF];
struct node
{
int x,y;
}f[FFF];
bool cmp(node a,node b){
if(a.x==b.x)
return a.y<b.y;
else
return a.x<b.x;
}
int main()
{
int n,p;
scanf("%d%d",&n,&p);
memset(cnt,,sizeof(cnt));
for(int i=;i<n;i++)
{
scanf("%d%d",&f[i].x,&f[i].y);
if(f[i].x>f[i].y)
{
int t=f[i].x;
f[i].x=f[i].y;
f[i].y=t;
}
cnt[f[i].x]++;
cnt[f[i].y]++;
}
for(int i=;i<=n;i++)to[i]=cnt[i];
long long ans=,now=n;
sort(cnt+,cnt+n+);
for(int i=;i<=n;i++) {
if(cnt[i]>=p)
ans+=n-;
else{
while(cnt[now]>=p-cnt[i])
now--;
if(cnt[now+]+cnt[i]>=p){
if(cnt[now+]>cnt[i])
ans+=n-now;
else
ans+=n-now-;
}
}
// cout<<"now="<<now<<" cnt[now]="<<cnt[now]<<" ans="<<ans<<endl;
}
ans/=;
sort(f,f+n,cmp);
node tmp;
tmp.x=tmp.y=;
memset(cnt,,sizeof(cnt));
int c=;
for(int i=;i<n;i++)
{
if(tmp.x==f[i].x&&tmp.y==f[i].y)
c++;
else
{
if(tmp.x&&to[tmp.x]+to[tmp.y]>=p&&to[tmp.x]&&to[tmp.x]+to[tmp.y]-c<p)
ans--;
tmp.x=f[i].x;
tmp.y=f[i].y;
c=;
}
// cout<<"tmp.x="<<tmp.x<<" tmp.y="<<tmp.y<<" ans="<<ans<<endl;
}
if(to[tmp.x]+to[tmp.y]>=p&&to[tmp.x]&&to[tmp.x]+to[tmp.y]-c<p)
ans--;
cout<<ans<<endl;
return ;
}

codeforces 421d bug in code的更多相关文章

  1. codeforce 421D D. Bug in Code

    题目链接: http://codeforces.com/problemset/problem/421/D D. Bug in Code time limit per test 1 secondmemo ...

  2. SQL Server 2017的Linked Server配置触发的bug“Exception Code = c0000005 EXCEPTION_ACCESS_VIOLATION”

    SQL Server 2017的Linked Server配置触发的bug"Exception Code    = c0000005 EXCEPTION_ACCESS_VIOLATION&q ...

  3. Bug in Code CodeForces - 420C (计数,图论)

    大意: 给定$n$结点无向图, 共n条边, 有重边无自环, 求有多少点对(u,v), 满足经过u和v的边数>=p 可以用双指针先求出所有$deg_u+deg_v \ge p$的点对, 但这样会多 ...

  4. Codeforces Gym 100015H Hidden Code 暴力

    Hidden Code 题目连接: http://codeforces.com/gym/100015/attachments Description It's time to put your hac ...

  5. IOS bug之Code Sign error:Provisioning profile

    刚才解决一个版本冲突的bug,记在了博客里,这让我想起了另外一个bug,当时犹豫公司的开发者账号过期了,我打开应用运行时提示Code Sign error:Provisioning profile   ...

  6. Bug in Code

    Coder-Strike 2014 - Finals (online edition, Div. 1) C:http://codeforces.com/problemset/problem/420/C ...

  7. 【Codeforces 1129C】Morse Code

    Codeforces 1129 C 题意:给一个0/1串,问它的每一个前缀中的每一个子串能解析成莫尔斯电码的串的种数. 思路:首先对于这个串构造后缀自动机,那么从起点走到每一个节点的每一条路径都代表了 ...

  8. CodeForces 614B Gena's Code

    #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm& ...

  9. 状压DP--Rotate Columns (hard version)-- Codeforces Round #584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2)

    题意:https://codeforc.es/problemset/problem/1209/E2 给你一个n(1-12)行m(1-2000)列的矩阵,每一列都可以上下循环移动(类似密码锁). 问你移 ...

随机推荐

  1. WinEdt打开UTF-8文件乱码问题——ctex[转]

    原来这么简单,mark一下! [转自:http://fstang.diandian.com/post/2012-04-17/40030401020] 其实这个问题网上文章已经有一大堆了...我只是记录 ...

  2. Delphi Excel

    用delphi写excel文件 2007-03-18 21:12 1.引用:      Excel2000, OleServer,Comobj, StdCtrls 2.声明变量:     ExcelA ...

  3. java常用正则表达式

    1.邮编 public static final String POSTAL_CODE = "^\\d{6}$"; 2. email(支持中文域名邮箱) 正则表达式  public ...

  4. 桂电在线-转变成bootstrap版2(记录学习bootstrap)

    下载bootstrap框架https://github.com/twbs/bootstrap 或者 http://getbootstrap.com/ 拷贝模板 修改基本模板 语言zh-cn,标题,描述 ...

  5. php简易计算器实例

    <html> <head> <title>PHP实现简单计算器</title> <meta http-equiv="Content-Ty ...

  6. Ubuntu启动错误Checking Battery State的处理

    一.问题描述 二.处理方法 方法一: 按下 ctrl + alt + F1,进入终端,使用管理员权限执行下列代码 sudo rm /etc/X11/xorg.conf sudo reboot 方法二: ...

  7. 移动端meta标签整理-备

    分类 在介绍移动端特有 meta 标签之前,先简单说一下 HTML meta 标签的一些知识. meta 标签包含了 HTTP 标题信息 (http-equiv) 和 页面描述信息 (name). h ...

  8. Android中自定义ListView无法响应OnItemClickListener中的onItemClick方法问题解决方案

    如果你的自定义ListViewItem中有Button或者Checkable的子类控件的话,那么默认focus是交给了子控件,而ListView 的Item能被选中的基础是它能获取Focus,也就是说 ...

  9. POJ Code the Tree 树的pufer编号

    Code the Tree Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2259   Accepted: 859 Desc ...

  10. Children's Day

    hdu4706:http://acm.hdu.edu.cn/showproblem.php?pid=4706 题意:让你打出3--10的N,这个N是由连续的小写字母组成的. 题解:直接模拟啊,水题啊. ...