题目链接: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. jBPM 6 开发 eclipse 插件安装

    jBPM 6 开发 eclipse 插件安装 概述 与之前的jBPM 5相比,jBPM 6 新引入的kjars及mavenized的特性,使流程开发设计与之前有了很大的不同,本文主要说明jBPM 6 ...

  2. C# 执行批处理文件(*.bat)的方法代码

    代码如下: static void Main(string[] args){    Process proc = null;    try    {                        st ...

  3. "Unable to get image data from canvas because the canvas has been tainted by cross-origin data"问题产生原因及解决办法

    一.问题描述: 在支持html5的浏览器中运行javascript脚本,脚本主要是操作网页上的标签canvas,出错的操作为, getImageData(img,……), chrome 下出错信息为: ...

  4. 如何禁用easyui-linkbutton 中的Click事件

    eg: <a id="btn" href="#" class="easyui-linkbutton" data-options=&qu ...

  5. mysql 中执行的 sql 注意字段之间的反向引号和单引号

    如下的数据表 create table `test`( `id` int(11) not null auto_increment primary key, `user` varchar(100) no ...

  6. 界面信息获取库的封装,记有爱UI助手的诞生

    距离上次写文章已经过去了10个月,这次把我最近做的一个东西的一些心得写下来吧. 上一篇文章写了MSAA技术对于QQ界面信息获取的相关知识,近一段时间我把这个技术包括一些其他的功能做了一个封装并准备公开 ...

  7. 网站商务通链接快速标识v1.0.js

    js代码为: function getSwt(keys){ try{ if(openZoosUrl&&typeof(openZoosUrl)=="function" ...

  8. JavaScript学习心得(七)

    一 创建事件监听器 开发人员往往使用事件和元素组合来命名事件处理函数. 创建事件监听器方法: 嵌入式事件处理器即将JavaScript函数赋值给HTML元素属性(不推荐使用:污染HTML:无法应用渐进 ...

  9. ubuntu 14.04 安装preforce

    官网: http://www.perforce.com/ http://www.perforce.com/support-services 1. 下载相关文件 http://filehost.perf ...

  10. opencv 构造训练器

    D:/face   构造face训练器为例 一:样本创建 训练样本分为正例样本和反例样本,其中正例样本是指待检目标样本,反例样本指其它任意图片. 负样本可以来自于任意的图片,但这些图片不能包含目标特征 ...