Difference Between Primes Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 860 Accepted Submission(s): 278 Problem Description All you know Goldbach conjecture.That is to say, Every even integer gr…
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4715 Difference Between Primes Description All you know Goldbach conjecture.That is to say, Every even integer greater than 2 can be expressed as the sum of two primes. Today, skywind present a new conje…
Difference Between Primes Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 528    Accepted Submission(s): 150 Problem Description All you know Goldbach conjecture.That is to say, Every even inte…
http://acm.hdu.edu.cn/showproblem.php?pid=4715 [code]: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> using namespace std; #define N 1000151 ]; ]; ]; ]; ; int lowbit(int i) { return i&-i; } void add(i…
题意:给出一个偶数(不论正负),求出两个素数a,b,能够满足 a-b=x,素数在1e6以内. 只要用筛选法打出素数表,枚举查询下就行了. 我用set储存素数,然后遍历set里面的元素,查询+x后是否还是素数. 注意,偶数有可能是负数,其实负数就是将它正数时的结果颠倒就行了. 代码: /* * Author: illuz <iilluzen[at]gmail.com> * Blog: http://blog.csdn.net/hcbbt * File: 10.cpp * Create Date:…
http://acm.hdu.edu.cn/showproblem.php?pid=4715 Difference Between Primes Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description All you know Goldbach conjecture.That is to say, Every even integer great…
#include <string.h> #include <stdio.h> const int maxn = 1000006; bool vis[1000006]; int pr[1000005]; int cnt = 1; int bs(int l, int r, int v) { int mid=(l+r)>>1; while(l < r) { if(pr[mid] < v) l = mid+1; else r = mid; mid= (l+r) &g…
Difference Between Primes Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3339    Accepted Submission(s): 953 Problem Description All you know Goldbach conjecture.That is to say, Every even int…
HDU  4548  美素数(打表)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88159#problem/H 题目: Description 小明对数的研究比较热爱,一谈到数,脑子里就涌现出好多数的问题,今天,小明想考考你对素数的认识.         问题是这样的:一个十进制数,如果是素数,而且它的各位数字和也是素数,则称之为“美素数”,如29,本身是素数,而且2+9 = 11也是素数,所以它是美素数.   …
HDU 5487 Difference of Languages 这题从昨天下午2点开始做,到现在才AC了.感觉就是好多题都能想出来,就是写完后debug很长时间,才能AC,是不熟练的原因吗?但愿孰能生巧吧. BFS转移的是两个DFA的状态,用typedef pair<int,int> pi;map<pi,pi> pres;      两步储存前后状态的链接. 附上一组测坑数据: /*4324 3 130 1 a1 2 e2 3 w6 3 150 1 a1 3 e3 5 h*/ #…
这道题很坑,注意在G++下提交,否则会WA,还有就是a或b中较大的那个数的范围.. #include<iostream> #include<cstdio> #include<cstring> using namespace std; const int maxn = 1e6 + 10; int prime[maxn]; bool isprime[maxn]; int init() { memset(prime, 0, sizeof(prime)); isprime[0]…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4715 思路:先打个素数表,然后判断一下就可以了. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; ]; ]; int main() { ; memset(isprime,true…
题目链接 题意 : 给出一个 x 和 k 问有多少个 y 使得 x = f(y, k) - y .f(y, k) 为 y 中每个位的数的 k 次方之和.x ≥ 0 分析 : f(y, k) - y = x ≥ 0 满足条件的 y 最多不超过 10 位 这个并不知道怎么证.网上有很多结论证明.仔细推敲过后发现都是错的 可能需要手动打表模拟一下吧...... 变化一下式子 x = f(a, k) - a + f(b, k) - b * (1e5) x - f(a, k) + a = f(b, k)…
YaoYao has a company and he wants to employ m people recently. Since his company is so famous, there are n people coming for the interview. However, YaoYao is so busy that he has no time to interview them by himself. So he decides to select exact m i…
Difference Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 62    Accepted Submission(s): 19 Problem Description Little Ruins is playing a number game, first he chooses two positive integers y an…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1535 Problem Description In the age of television, not many people attend theater performances. Antique Comedians of Malidinesia are aware of this fact. They want to propagate theater and, most of all,…
HDU 2563 统计问题 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u HDU 2563 Description 在一无限大的二维平面中,我们做如下假设: 1.  每次只能移动一格: 2.  不能向后走(假设你的目的地是“向上”,那么你可以向左走,可以向右走,也可以向上走,但是不可以向下走): 3.  走过的格子立即塌陷无法再走第二次: 求走n步不同的方案数(2种走法只要有一步不一样,即…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=4548 Problem Description 小明对数的研究比较热爱,一谈到数,脑子里就涌现出好多数的问题,今天,小明想考考你对素数的认识. 问题是这样的:一个十进制数,如果是素数,而且它的各位数字和也是素数,则称之为“美素数”,如29,本身是素数,而且2+9 = 11也是素数,所以它是美素数. 给定一个区间,你能计算出这个区间内有多少个美素数吗?   Input 第一行输入一个正整数T,表示总共有T组…
find the most comfortable road Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3999    Accepted Submission(s): 1720 Problem Description XX 星有许多城市,城市之间通过一种奇怪的高速公路SARS(Super Air Roam Structure---超…
GTW likes function 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5596 Description Now you are given two definitions as follows. f(x)=∑xk=0(−1)k22x−2kCk2x−k+1,f0(x)=f(x),fn(x)=f(fn−1(x))(n≥1) Note that φ(n) means Euler's totient function.(φ(n)is an…
Problem Description All you know Goldbach conjecture.That is to say, Every even integer greater than 2 can be expressed as the sum of two primes. Today, skywind present a new conjecture: every even integer can be expressed as the difference of two pr…
题目链接: http://poj.org/problem?id=2607 Description A city is served by a number of fire stations. Some residents have complained that the distance from their houses to the nearest station is too far, so a new station is to be built. You are to choose t…
http://acm.hdu.edu.cn/showproblem.php?pid=5936 题意: 定义了这样一种算法,现在给出x和k的值,问有多少个y是符合条件的. 思路: y最多只有10位,再多x就是负的了. 这样的话可以将y分为前后两部分,我们先枚举后5位的情况,然后再枚举前5位的情况,通过二分查找找到匹配的项,这样就大大的降低了时间复杂度. #include<iostream> #include<algorithm> #include<cstring> #in…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1043 题目大意:传统八数码问题 解题思路:就是从“12345678x”这个终点状态开始反向BFS,将各个状态记录下来,因为数字太大所以用康托展开将数字离散化. 代码: #include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<string> #…
King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember history, King plans to play losephus problem in the parade gap.He calls n(1≤n≤5000) soldiers, counterclockwise in a circle, in label 1,2,3...n. The firs…
Difference of Languages Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 548764-bit integer IO format: %I64d      Java class name: Main A regular language can be represented as a deterministic finite automaton…
Smallest Difference Description Given a number of distinct decimal digits, you can form one integer by choosing a non-empty subset of these digits and writing them in some order. The remaining digits can be written down in some order to form a second…
HDU 4173 题意:已知n(n<=200)位參赛选手的住所坐标.现要邀请尽可能多的选手来參加一个party,而每一个选手对于离住所超过2.5Km的party一律不去,求最多能够有多少个选手去參加party. 思路: 最好还是先考虑party可能的位置,要尽可能多的邀请到选手參加,则仅仅需考虑party所在位置在某两位住所连线的中点上或某选手住所所在位置,由于这是最大參加party选手数非常有可能在的位置. 若其它位置能得到最大參加选手数.那么中点或选手住所也一定可得到. //反证法可得.试着…
题意 求区间l,r的子串在原串中第k次出现的位置. 链接:https://vjudge.net/contest/322094#problem/C 思路 比赛的时候用后缀自动机写的,TLE到比赛结束. 学了后缀数组后,发现这题用后缀数组写还简单些. 我们把样例aaabaabaaaab后缀排序后列出来: 比如我们的l,r,k为2,3,2,那么先找到2,3表示的子串为aa,后缀数组的height数组表示的是相邻两个后缀(排序后)的最长公共前缀长度,往这个方向去想,[l,r]这个子串肯定是某个后缀的前缀…
Difference of Clustering HDU - 5486 题意:有n个实体,新旧两种聚类算法,每种算法有很多聚类,在同一算法里,一个实体只属于一个聚类,然后有以下三种模式. 第一种分散,新算法的某几个聚类是旧算法某个聚类的真子集. 第二种聚合,旧算法的某几个聚类是新算法某个聚类的真子集. 第三种1:1,新算法的某个聚类跟旧算法某个聚类相同. 问每种模式存在多少个? 实路上很明了,就是模拟,而且每个实体最多遍历到一次,所以时间上不用担心. 先把聚类的编号hash,把每个实体分配到相应…