HDU 5101】的更多相关文章

http://acm.hdu.edu.cn/showproblem.php?pid=5101 给n个集合,选择两个来自不同集合的数,加和大于k,问有多少种选择方案. 答案=从所有数中选择的两个加和大于k的数的方案数-在同一个集合中选择的两个加和大于k的数的方案数 而对于同一个集合中选择的两个加和大于k的方案数是可以直接排序然后利用单调性快速统计出来的. 注意upper_bound的应用和ans要使用long long因为10^5*10^5/2超界限了.. #include <iostream>…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5101 题目意思:给出 n 个 classes 和 Dudu 的 IQ(为k),每个classes 都有相应的人,每个人又有相应的IQ.现在要求从这些classes挑选两个人,满足IQ之和 > k,不过要满足这两个人不能来自同一个class的. 解题思路不难想出,直接所有人两两之和 > k - 同一个class 两两之和 > k  就是答案了. 不过很容易超时!!!! 用二分就可以过了.二分有…
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5101 Select 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 t…
题意:n 组,每组有一些值,求 在不同的两组中每组选一个使值的和大于k的方法数. 解法:n * Cnt[n] <= 1000*100 = 100000, 即最多10^5个人,所以枚举每个值x,求他的后面那些组中有多少数大于 k-x即可, 求有多少数大于k-x可以先求有多少数小于等于k-x,然后总数减一下即可. 可以用树状数组求. 先把所有数离散地存入一个树状数组中,然后每次枚举完一组的数后,将这组的数去掉. 代码: #include <iostream> #include <cst…
Select                                                    Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)                                                                    Total Submission(s): 285    Accepted Subm…
Select Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1599    Accepted Submission(s): 443 Problem Description One day, Dudu, the most clever boy, heard of ACM/ICPC, which is a very interesting…
hdoj5101 lower_bound函数: 题意: 从两个不同集合拿出两个数,加的和大于k的可行的方案数 思路: 答案=从所有数中选择的两个加和大于k的数的方案数-在同一个集合中选择的两个加和大于k的数的方案数 对于同一个集合中选择的两个加和大于k的方案数, 直接排序, 然后利用单调性快速统计出来的. ------------------------. #include<iostream> #include<cstdio> #include<stdlib.h> #i…
题意: 多多有一个智商值K. 有n个班级,第i个班级有mi个人.智商分别是v1,v2,.....vm. 多多要从这些人中选出两人.要求两人智商和大于K,并且两人不同班.问总共有多少种方案. 数据范围: n ( 0≤n≤1000 ), k( 0≤k<2^31 ) m( 0≤m≤100 ), v[i]( 0≤v[i]<2^31 ) 思路: 对于一个单调长的序列,可以很容易地统计两数之和大于K的对数(枚举第一个数,二分找到满足条件的最小的数的位置,然后它和它后面的数都是满足条件的) 故对于每个班内,…
链接:https://www.nowcoder.com/acm/contest/84/F 来源:牛客网 题目描述 给定n个数,从中选出三个数,使得最大的那个减最小的那个的值小于等于d,问有多少种选法. 输入描述: 第一行两个整数n,d(1 <= n <= 100,000,1 <= d <= 1000,000,000): 第二行n个整数满足abs(ai) <= 1,000,000,000.数据保证a单调递增. 输出描述: 输出一个整数表示满足条件的选法. 示例1 输入 4 3…
Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5101    Accepted Submission(s): 2339 Problem Description Mario is world-famous plumber. His “burly” figure and amazing jumping abilit…
Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7194    Accepted Submission(s): 3345 Problem Description 话说上回讲到海东集团面临内外交困,公司的元老也只剩下XHD夫妇二人了.显然,作为多年拼搏的商人,XHD不会坐以待毙的.  一天,当他正在苦思冥想解困良策的…
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef long long ll; int jc[100003]; int p; int ipow(int x, int b) { ll t = 1, w = x;…
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格线满足两侧分别是海洋和陆地 这道题很神 首先考虑一下,什么情况下能够对答案做出贡献 就是相邻的两块不一样的时候 这样我们可以建立最小割模型,可是都说是最小割了 无法求出最大的不相同的东西 所以我们考虑转化,用总的配对数目 - 最小的相同的对数 至于最小的相同的对数怎么算呢? 我们考虑这样的构造方法:…
Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4569 Description Let f(x) = a nx n +...+ a 1x +a 0, in which a i (0 <= i <= n) are all known integers. We call f(x) 0 (mod…
The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4006 Description Xiao Ming and Xiao Bao are playing a simple Numbers game. In a round Xiao Ming can choose to write down a nu…
How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1796 Description   Now you get a number N, and a M-integers set, you should find out how many integers which are sm…
(转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pid=4418 读了一遍题后大体明白意思,但有些细节不太确定.就是当它处在i点处,它有1~m步可以走,但他走的方向不确定呢.后来想想这个方向是确定的,就是他走到i点的方向,它会继续朝着这个方向走,直到转向回头. 首先要解决的一个问题是处在i点处,它下一步该到哪个点.为了解决方向不确定的问题,将n个点转…
1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/article/details/22569639 这个题目本身简单,我的想法也很easy,但是发生在测试上,我把memset的参数搞错了,第三个是sizeof(a), 比如说int a[10],第三个参数应该是sizeof(10),也就是40,而我传的是10,导致后面的测试,都是答案错误,也就是后面的数据,初始…
problem:http://acm.hdu.edu.cn/showproblem.php?pid=4329 题意:模拟  a.     p(r)=   R'/i   rel(r)=(1||0)  R是前n次输入有关URL的个数  R'是后n次已经输入有关URL的个数 b.   另加:输入 istringstream #include<iostream> #include<sstream> //istringstream 必须包含这个头文件 #include<string&g…
http://acm.hdu.edu.cn/showproblem.php?pid=2586 题意:求最近祖先节点的权值和 思路:LCA Tarjan算法 #include <stdio.h> #include <string.h> #define maxn 40005 ],pos,dist[maxn],f[maxn]; bool vis[maxn]; struct Edge{ int to,val,next; }edge[maxn*]; void add(int u,int v,…
http://acm.hdu.edu.cn/showproblem.php?pid=1429 一个广搜的简单题吧,不过有意思的事这个题目用到了位运算,还有就是很恶心的MLE #include <stdio.h> #include <string.h> #include <queue> using namespace std; int m,n,t; ][]; ][][<<]; ][] = {-,,,,,-,,}; struct note{ int x,y,st…
http://acm.hdu.edu.cn/showproblem.php?pid=1878 题意:就是判断这个图是不是一个欧拉回路的一个题, 思路:我觉得这个题可以用并查集判环加上判断每个点的度就行了 #include <stdio.h> #include <string.h> #include <queue> using namespace std; ]; ]; int Find(int x) { int _x=x,_b; while( _x != belg[ _x…
hdu5901题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5901 code vs 3223题目链接:http://codevs.cn/problem/3223/ 思路:主要是用了一个Meisell-Lehmer算法模板,复杂度O(n^(2/3)).讲道理,我不是很懂(瞎说什么大实话....),下面输出请自己改 #include<bits/stdc++.h> using namespace std; typedef long long LL;…
链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=2191 思路:多重背包模板题 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <algorithm> using namespace std; int money,type; ],weigh[],num[],dp[]; i…
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5384 思路:没学自动机时以为是道KMP然后就tle了好几把,AC自动机模板题 #include<cstdio> #include<iostream> #include<algorithm> #include<math.h> #include<string.h> #include<vector> #include<queue> #i…
链接:http://acm.hdu.edu.cn/showproblem.php?pid=2222 思路:裸AC自动机,直接贴代码做模板 #include<stdio.h> #include<string.h> #include<malloc.h> #include<queue> using namespace std; +]; struct node { int count; ]; struct node *fail; void init() { int…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4467 题意:给定n个点m条边的无向图,点被染色(黑0/白1),边带边权.然后q个询问.询问分为两种: Change u:把点u的颜色反转(黑变白,白变黑),Asksum a b(a,b的值为0/1):统计所以边的权值和,边的两个点满足一个点的颜色为a,一个点的颜色为b. 思路:考虑暴力的做法.修改可以做法O(1),但是查询就得O(m).所以总复杂度为O(m*q)会TLE.然后考虑图分块.参考HDU…
直达–> HDU 1495 非常可乐 相似题联动–>POJ 3414 Pots 题意:中文题,不解释. 思路:三个杯子倒来倒去,最后能让其中两个平分即可.可能性六种.判定的时候注意第三个杯子不能有水,倒的时候也要注意别超过了倒进去的杯子的容积. a->b || a->c || b->a || b->c || c->a || c->b #include <cstdio> #include <cstring> #include <q…
HDU 1257 最少拦截系统 题意:中文题不解释. 思路:网上有说贪心有说DP,想法就是开一个数组存每个拦截系统当前最高能拦截的导弹高度.输入每个导弹高度的时候就开始处理,遍历每一个拦截系统,一旦最高拦截高度比它高,就把当前拦截系统的高度调整为它的高度,如果访问到末尾都没有能拦截的系统,那么拦截系统加一. P.S:听说这题杭电数据有点水 /** Sample Input 8 389 207 155 300 299 170 158 65 Sample Output 2 **/ #include…
HDU 1260 Tickets 题意:有N个人要买票,你可以一个一个人卖票,时间分别为Xs,也可以相邻两个人一起卖票,时间为Ys,从早上八点开始卖票,问你何时最早将N个人的票卖完. 思路:解决情况是当前最优,要么就单卖,状态最优就是前一个人的,要么和前一个人一起拼凑,状态最优是前两个人的,取时间最短的. 时间显示问题,注意下上下午的事情就好了. dp[i] = min(dp[i-1]+signal[i],dp[i-2]+unit[i]) /** Sample Input 2 2 20 25 4…