codeforces 421d bug in code
题目链接: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的更多相关文章
- codeforce 421D D. Bug in Code
题目链接: http://codeforces.com/problemset/problem/421/D D. Bug in Code time limit per test 1 secondmemo ...
- 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 ...
- Bug in Code CodeForces - 420C (计数,图论)
大意: 给定$n$结点无向图, 共n条边, 有重边无自环, 求有多少点对(u,v), 满足经过u和v的边数>=p 可以用双指针先求出所有$deg_u+deg_v \ge p$的点对, 但这样会多 ...
- Codeforces Gym 100015H Hidden Code 暴力
Hidden Code 题目连接: http://codeforces.com/gym/100015/attachments Description It's time to put your hac ...
- IOS bug之Code Sign error:Provisioning profile
刚才解决一个版本冲突的bug,记在了博客里,这让我想起了另外一个bug,当时犹豫公司的开发者账号过期了,我打开应用运行时提示Code Sign error:Provisioning profile ...
- Bug in Code
Coder-Strike 2014 - Finals (online edition, Div. 1) C:http://codeforces.com/problemset/problem/420/C ...
- 【Codeforces 1129C】Morse Code
Codeforces 1129 C 题意:给一个0/1串,问它的每一个前缀中的每一个子串能解析成莫尔斯电码的串的种数. 思路:首先对于这个串构造后缀自动机,那么从起点走到每一个节点的每一条路径都代表了 ...
- CodeForces 614B Gena's Code
#include <stdio.h> #include <string.h> #include <iostream> #include <algorithm& ...
- 状压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)列的矩阵,每一列都可以上下循环移动(类似密码锁). 问你移 ...
随机推荐
- Linux中一些目录名称的含义
挖Linux中的古老缩略语[2005-06-22 15:23][Nigel McFarlane][TechTarget] Unix已经有35年历史了.许多人认为它开始于中世纪,这个中世纪是相对于计算机 ...
- Redhat linux DNS配置指南(SCANIP配置手册)
在oracle 11g的RAC中增加了SCAN IP,而使用 SCAN IP的一种方式就是使用DNS,这里介绍在Redhat Linux 5.4中DNS的详细配置操作在配置DNS之前修改主机名Redh ...
- oracle编译 失效对象方式
如果procedure 所使用的表结构发生了改变等其它情况,在相应的xxx_objects表的status字段会变为invalid状态,但是如果在调用时procedure会自动编译,grant失效对象 ...
- DevExpress XtraGrid RepositoryItemCheckEdit 复选框多选的解决方法
1. RepositoryItemCheckEdit默认有三种状态,选中状态.未选中状态和半选中状态(半选中状态通常用在TreeList中如果父节点下的子节点有选中的有未选中的,则父节点状态为半选中状 ...
- JavaScript Invalid Date Verify
if ( Object.prototype.toString.call(d) === "[object Date]" ) { // it is a date if ( isNaN( ...
- 图像载入 imread()[OpenCV 笔记4]
Mat imread( ); filename 载入的图像名: flags 指定加载图像的颜色类型,默认载入三通道彩色图像, 如果取枚举类型 (OpenCV3中暂时失效),则定义如下 enum{ CV ...
- Android Studio 中解决.9图片报错的问题
- 开发错误日志之No matching bean of type [xxx] found for dependency
No matching bean of type [org.springframework.data.mongodb.core.MongoTemplate] found for dependency ...
- java 优化
代码优化,一个很重要的课题.可能有些人觉得没用,一些细小的地方有什么好修改的,改与不改对于代码的运行效率有什么影响呢?这个问题我是这么考虑的,就像大海里面的鲸鱼一样,它吃一条小虾米有用吗?没用,但是, ...
- PHP表单常用正则表达式(URL、HTTP、手机、邮箱等)
<?php /** * @description: 正则表达式匹配 */ class Regex { /** * @手机号 */ public static function Phone($su ...