随笔分类 -  组合 --- 容斥原理

hdu 2461 Rectangles
摘要:求矩形的并 矩形个数 1...20m次询问 回答要求的r个矩形的并容斥原理dfs优化: 遇到面积交为0时 这个dfs分支可以不下去了#include #include #include#include #include #include #include #include using namespace std;//#define LL long long#define LL __int64struct Rectan{ int x1,y1; int x2,y2; Rectan jiao(Rectan &R) { Rectan t; t.x1... 阅读全文

posted @ 2014-03-25 17:22 江财小子 阅读(161) 评论(0) 推荐(0)

Scoi 2010 幸运数字
摘要:【题目描述】在中国,很多人都把6和8视为是幸运数字!lxhgww也这样认为,于是他定义自己的“幸运号码”是十进制表示中只包含数字6和8的那些号码,比如68,666,888都是“幸运号码”!但是这种“幸运号码”总是太少了,比如在[1,100]的区间内就只有6个(6,8,66,68,86,88),于是他又定义了一种“近似幸运号码”。lxhgww规定,凡是“幸运号码”的倍数都是“近似幸运号码”,当然,任何的“幸运号码”也都是“近似幸运号码”,比如12,16,666都是“近似幸运号码”。现在lxhgww想知道在一段闭区间[a, b]内,“近似幸运号码”的个数。【输入】输入数据是一行,包括2个数字a和b 阅读全文

posted @ 2014-03-25 17:00 江财小子 阅读(439) 评论(0) 推荐(0)

poj 1426 Find The Multiple
摘要://给你一个整数 1#include #include #include #include #include #include #include using namespace std;#define LL __int64//#define LL long long#define N 1010struct node{ int num; int fa; int lf;}No[N];int h[210];void output(int id){ if(id) { output(No[id].fa); printf("%d",No[id].n... 阅读全文

posted @ 2014-03-23 22:27 江财小子 阅读(153) 评论(0) 推荐(0)

hdu 1695 GCD
摘要:// 题意: 给你区间[a,b] [c,d] 在两个区间各取一个数x,y,要求gcd(x,y)= k// 题目给的区间中说 0 #include #include#include #include #include #include #include using namespace std;#define LL __int64//#define LL long long#define N 100010struct node{ int cnt; int pr[10];}hs[N];LL phi[N];LL ans;void init(){ int i,j; for(i... 阅读全文

posted @ 2014-03-23 21:42 江财小子 阅读(155) 评论(0) 推荐(0)

poj 3370 Halloween treats
摘要://poj 3370 c个小孩 n户人家 n>=c 每个人家有一些糖果,找些人家糖果和是c的倍数 输出找到人家的编号 (从1开始计算)//鸽巢原理// n个数必定存在某段连续和是n的倍数// 累加求余可以看出这个#include #include #include using namespace std;#define LL __int64LL a[100010];int h[100010];int main(){ int c,n; while(scanf("%d%d",&c,&n),c|n) { // printf("%lld\n" 阅读全文

posted @ 2014-03-23 20:43 江财小子 阅读(137) 评论(0) 推荐(0)

uestc 1720无平方因子数
摘要:求素数 然后容斥原理// n之内有平方因子的数的个数sum =n/(2^2) + n/(3^2)+……+n/(k^2) - n/(2^2 * 3^2)-……+…….// #pragma comment(linker, "/STACK:1024000000,1024000000")#include #include #include #include #include #include #include using namespace std;#define MOD 1000000007#define maxn 1000010#define maxm 1000010#defi 阅读全文

posted @ 2013-07-27 11:33 江财小子 阅读(495) 评论(0) 推荐(0)

hdu 2204 Eddy's爱好
摘要:// 一个整数N,110^18 所以最多只取3个素数#include #include #include #include #include #include #include using namespace std;#define maxm 100010#define maxn 1000110int prim[110]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59};// 17个int main(){ int i,j,ct,mid; int rc[5]; __int64 n,m,ans,tp; while(scanf(... 阅读全文

posted @ 2013-07-25 10:10 江财小子 阅读(173) 评论(0) 推荐(0)

Hdu 4407 Sum
摘要:SumTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 897Accepted Submission(s): 259Problem DescriptionXXX is puzzled with the question below: 1, 2, 3, ..., n (1#include #include #include #include #include #include using namespace std;bool h[700];int 阅读全文

posted @ 2012-10-19 18:47 江财小子 阅读(343) 评论(0) 推荐(0)