题目链接: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. Repeater 动态增加删除一行

    文章参考:文章参考http://www.cnblogs.com/dataadapter/archive/2012/06/25/2562885.html 效果: 前台代码: <%@ Page La ...

  2. 回退符\b

    回退符\b #include <stdio.h> int main(){ printf("hello\b"); getchar(); getchar(); ; } 实验 ...

  3. SVM(支持向量机)算法

    第一步.初步了解SVM 1.0.什么是支持向量机SVM 要明白什么是SVM,便得从分类说起. 分类作为数据挖掘领域中一项非常重要的任务,它的目的是学会一个分类函数或分类模型(或者叫做分类器),而支持向 ...

  4. Linux 消息队列编程

    消息队列.信号量以及共享内存被称作 XSI IPC,它们均来自system V的IPC功能,因此具有许多共性. 键和标识符: 内核中的每一种IPC结构(比如信号量.消息队列.共享内存)都用一个非负整数 ...

  5. Asp.net服务器控件在IE10下的不兼容问题

    Asp.net服务器控件在IE10下的不兼容问题 时间:2013-05-16 09:07点击: 89 次 [大 中 小] 相信很多使用IE10的童鞋们已经发现了这个问题,以下是本人在IE10标准模式下 ...

  6. javascript 一串DIV跟随鼠标移动

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  7. 安装指南【win10下安装fedora】

    系统安装 安装准备 系统:fedora .Win 10 硬件:U盘一枚.PC一台 软件:UltraISO 安装步骤 使用UltraISO将镜像写入U盘 window10使用磁盘管理,空出一个未分配的区 ...

  8. 数据库基本概念-oracle介绍

    甲骨文公司,全称甲骨文股份有限公司是全球最大的企业软件公司,总部位于美国加利福尼亚州的红木滩.甲骨文是继Microsoft及IBM后,全球收入第三多的软件公司.甲骨文公司1989年正式进入中国市场.重 ...

  9. #Leet Code# Root to leaf

    语言:Python 描述:使用递归实现 def getList(self, node): if node is None: return [] if node.left is None and nod ...

  10. PDF转图片 C# with Adobe API

    PDF转图片大概有十几种方式,褒贬不一,我就详细给大家说一下我认为效率最高的方式,使用Adobe官方的SDK 安装acrobat reader 9.0以上即可,勾选如下组件.