摘要:题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4712首先,算汉明距离就是二进制异或以后的1的个数,统计1的个数用x&=x-1很快很神奇。用if(x&1) {count++; x>>=1;} 在位数比较多的时候会慢一些。然后就是看题解学到的神奇的“随机”! 来取到“任意的两个” 1w次wa,但是10w次就不会,20组testcase ,不会超时;真的ac了,很神奇代码:#include#include#include#include#includeusing namespace std;int a[100005];in
阅读全文
摘要:题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4708首先来学习一个ac的代码:作者http://blog.csdn.net/xingyeyongheng#include#include#include#include#include#include#include#include#define INF 99999999using namespace std;const int MAX=10;int s[MAX][MAX];int main(){ int n; while(scanf("%d",&n),n){ for(
阅读全文
摘要:题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4715首先打素数表,然后分三类 x=0,>0, #include#includeusing namespace std;#define N 10000000bool p[N+1];void pre(){ int d=sqrt(N); for(int i=2;i>n; for(int i=0;i0) { for(start=2;start<=10000000-x;start++) { if(!p[st...
阅读全文
摘要:题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4707题目给出一颗树,要求求出深度大于D的结点的个数。有两种方法,改写dfs,给一个参数放层数(额,其实这里不需要转化为有根树,多余了)代码:#include#include#include#includeusing namespace std;#define maxn 100005vector G[maxn];int p[maxn];int lev[maxn];//vector leaf;void dfs(int u,int fa,int level) // 无根树转化为有根树{ in...
阅读全文
摘要:题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4706用一个三维数组来存贮要表示的矩阵,先画几个特例找规律,记住这个N是倒的...代码:#include#includeusing namespace std;char p[11][11][11];int main(){ for(int i=1;i#include#includeusing namespace std;int a[100][100];bool vis[100][100];void init(){ memset(vis,0,sizeof(vis));}int main(){...
阅读全文
摘要:题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4709可以证明,三角形是最小的。直接计算三角形面积,取最小的的,Impossible的情况特判就行。计算三角形面积用向量叉积。代码:#include#include#include#include#includeusing namespace std;struct point{ double x; double y;};double area(point A,point B,point C){ double abx=B.x-A.x; double aby=B.y-A.y; d...
阅读全文
摘要:题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4706以前做过的题目: i从0到n-1时,如果一个一个加会很慢,注意到如果mod a的序列 和mod b的序列都处在上升中,那么差距是一样的,这样跳的step就可以大一些~注意下就是如果a,b都是1的话 ,跳步还是没有变动,直接特判为0就行。 还有step*(i%a-i%b)可能会超int 其中一个要用long long 存放代码:#include#includeusing namespace std;int min(int a,int b){ if(a>T; while(T--) { ...
阅读全文