cf660c Select 二分 思维
来源:互联网 发布:最好小额网络理财投资 编辑:程序博客网 时间:2024/05/18 15:29
Description
One day, Dudu, the most clever boy, heard of ACM/ICPC, which is a very interesting game. He wants to take part in the game. But as we all know, you can’t get good result without teammates.
So, he needs to select two classmates as his teammates.
In this game, the IQ is very important, if you have low IQ you will WanTuo. Dudu’s IQ is a given number k. We use an integer vii to represent the IQ of the ith classmate.
The sum of new two teammates’ IQ must more than Dudu’s IQ.
For some reason, Dudu don’t want the two teammates comes from the same class.
Now, give you the status of classes, can you tell Dudu how many ways there are.
Input
There is a number T shows there are T test cases below. (T≤20T≤20)
For each test case , the first line contains two integers, n and k, which means the number of class and the IQ of Dudu. n ( 0≤n≤10000≤n≤1000 ), k( 0≤k<2310≤k<231 ).
Then, there are n classes below, for each class, the first line contains an integer m, which means the number of the classmates in this class, and for next m lines, each line contains an integer vii, which means there is a person whose iq is vii in this class. m( 0≤m≤1000≤m≤100 ), vii( 0≤v[i]<2310≤v[i]<231 )
Output
For each test case, output a single integer.
Sample Input
1
3 1
1 2
1 2
2 1 1
Sample Output
5
Hint
题意
看样例就知道了 改变k次0
问最大长度的连续1序列
题解:
三个特判
k==0 k==n
还有原序列k小于n 都是0的
AC代码
#include <cstdio>#include <iostream>#include <queue>#include <map>#include <cmath>#include <cstring>#include <algorithm>using namespace std;typedef long long LL;const int N = 3e5+5;int a[N];int sum[N];int n,k;bool check(int t){ int cnt = n; for (int i = 1; i <= n-t+1; ++i){ if (t>=(sum[i+t-1]-sum[i-1])){ cnt = min(cnt,t-(sum[i+t-1]-sum[i-1])); } } if (cnt>k) return false; return true;}int main(){ int aa = 1; int sk = 1; int ff = 1; scanf("%d%d",&n,&k); for (int i = 1; i <= n; ++i){ scanf("%d",&a[i]); sum[i] = sum[i-1]+a[i]; if (a[i]==a[i-1]&&a[i]==1){ aa++; sk = max(aa,sk); }else aa = 1; if (a[i]==1) ff = 0; } if (ff) sk=0; int l = 0,r = n; while (l<=r){ int mid = (l+r)>>1; if (!check(mid)) r = mid-1; else l = mid+1; } if (k==0) printf("%d\n",sk); else printf("%d\n",l-1); int fg = 0; int ct = 0; if (n==k){ for (int i = 1; i <= n; ++i){ if (i==1) printf("1"); else printf(" 1"); } } else for (int i = 1; i <= n; ++i){ if (l-1-(sum[i+l-2]-sum[i-1])==k&&fg==0){ fg = 1; ct = l; } if (ct > 1){ if (i==1) printf("1"); else printf(" 1"); ct--; }else if(i==1) printf("%d",a[i]); else printf(" %d",a[i]); } printf("\n"); return 0;}
- cf660c Select 二分 思维
- HDU5102 Select 二分 思维
- hdoj 5101 Select 【二分 + 思维】
- CodeForces807c_二分+思维
- Drying<二分,思维题>
- hihocoder1543(思维+ 二分)
- HDU5101 Select(二分)
- HDU 5101 Select 二分
- 【HPU 1193 Interval】+ 二分 + 思维
- CodeForces 672D (思维+二分)
- hdu-5726 GCD 思维||二分
- HDU 5101 Select (二分)
- HDU 5101Select(暴力二分)
- HDU 5101 Select (二分)
- hdu 5101 Select【二分查找】
- HDU 5101 Select(二分)
- HDU 5101 Select(二分)
- 51NOD 1279 扔盘子(二分 + 思维)
- 机器人技术与应用笔记
- 【安卓基础】02Android四种基本布局
- 查找三 多路查找树(2-3树,2-3-4树,B树、B+树)
- android应用开机自启、更新自启,process进程清空缓冲区
- 群体智能——激发更多潜能
- cf660c Select 二分 思维
- 前端页面处理分辨率的方法
- 2017多校联合第一场 1006题 hdu 6038 Function 循环节
- Java编写一个用于表示战斗能力的接口练习题 含有随机数的比较
- Linux之top命令详解
- hadoop1中partition和combiner作用
- LIN总线(一)
- Linux用户管理
- (3)php爬虫---mysql大批数据导入数据库-4种方法比较