hdu 5101(思路题)
Select
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1599 Accepted Submission(s): 443
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 v[i] 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.
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≤1000 ), k( 0≤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 v[i], which means there
is a person whose iq is v[i] in this class. m( 0≤m≤100 ), v[i]( 0≤v[i]<231 )
3 1
1 2
1 2
2 1 1
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int N = ;
const int M = ;
int v[M];
int v1[N*M];
int sum[N];
struct Node{
int num;
int v[N];
}node[N];
int main(){
int tcase,n;
int k;
scanf("%d",&tcase);
while(tcase--){
scanf("%d%d",&n,&k);
int cnt = ;
for(int i=;i<=n;i++){
scanf("%d",&node[i].num);
sum[i] = sum[i-]+node[i].num;
for(int j=;j<=node[i].num;j++){
scanf("%d",&v[j]);
v1[cnt++] = v[j];
}
sort(v+,v+node[i].num+);
for(int j=;j<=node[i].num;j++){
node[i].v[j] = v[j];
}
}
sort(v1+,v1+cnt);
long long ans = ;
for(int i=;i<=n;i++){
for(int j=;j<=node[i].num;j++){
int v = node[i].v[j];
int pos1 = node[i].v+node[i].num+ - lower_bound(node[i].v+,node[i].v++node[i].num,k-v+);
int pos2 = v1+cnt - lower_bound(v1+,v1+cnt,k-v+);
ans += pos2-pos1;
}
}
printf("%lld\n",ans/);
}
return ;
}
hdu 5101(思路题)的更多相关文章
- hdu 4908(思路题)
BestCoder Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- Proud Merchants HDU - 3466 (思路题--有排序的01背包)
Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerfu ...
- hdu 5191(思路题)
Building Blocks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- hdu 5063(思路题-反向操作数组)
Operation the Sequence Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- hdu 4859(思路题)
Goffi and Squary Partition Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- hdu 4956(思路题)
Poor Hanamichi Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu 5400(思路题)
Arithmetic Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- HDU 1173 思路题
题目大意 有n个地点(坐标为实数)需要挖矿,让选择一个地点,使得在这个地方建造基地,到n个地点的距离和最短,输出基地的坐标. 题解+代码: 1 /* 2 把这个二维分开看(即把所有点投影到x轴上,再把 ...
- 51nod P1305 Pairwise Sum and Divide ——思路题
久しぶり! 发现的一道有意思的题,想了半天都没有找到规律,结果竟然是思路题..(在大佬题解的帮助下) 原题戳>>https://www.51nod.com/onlineJudge/ques ...
随机推荐
- Django基本使用
目录 1 安装 1.1 安装pip 1.2 安装django 2 创建项目 2.1 使用 管理工具 django-admin.py 来创建 PyLearn 项目: 2.2 启动服务 本文章以下所有列子 ...
- 通过学习制作长微博工具来了解水印的制作,及EditText中的内容在图片中换行显示
长微博工具非常有用,140字的要求可能阻止你写更多的内容,于是长微博工具应运而生,虽然网上有很多长微博工具,但是我都不是很满意,所以自己想做一个,通过做这个长微博工具,我学习到了很多东西,有两个难点, ...
- shell脚本获取网页快照并生成缩略图
获取网页快照并生成缩略图可分两步进行: 1.获取网页快照 2.生成缩略图 获取网页快照 这里我们用 phantomjs 来实现.关于 phantomjs 的详细用法可参考官方网站. 1.安装 我的环境 ...
- CSS系列(8) CSS后代选择器和子选择器详解
一.CSS后代选择器详解 1, 生动介绍基本概念 一个标签嵌B在另一个标签A内部,B就是A的后代. 而且,B的后代也是A的后代,这就叫“子子孙孙无穷尽也”. 比如: <div> < ...
- android surfaceview 入门介绍
由于工作中需自定义控件,以前没写过. 开始时,实用view 实现了,经理说不好,担心效率低,要求每秒需要刷新10次左右. 然后,学习使用 surfaceview. 看了网上简单的Demo,找到him ...
- 【Search in Rotated Sorted Array II 】cpp
题目: Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed? Would t ...
- MQ消息中间件
MQ是什么? MQ是Message Queue消息队列的缩写.消息队列是一种应用程序对应用程序的通信方法.应用程序通过写和检索入列队的针对应用程序的数据(消息)来进行通信,而不需要专用连接来链接它们. ...
- Python 协程与事件循环
Table of Contents 前言 协程 async & await 事件循环 asyncio 的事件循环 结语 参考链接 前言 Python 标准库 asyncio 是我目前接触过的最 ...
- winform小知识
1.得到控制台或者winform程序在debug目录下生成的exe路径 建议使用:AppDomain.CurrentDomain.BaseDirectory或者Assembly.GetExecutin ...
- CentOS修改IP地址
一.CentOS 修改IP地址修改对应网卡的IP地址的配置文件 # vi /etc/sysconfig/network-scripts/ifcfg-eth0 电信 # vi /etc/syscon ...