soj 1088. Cows(树状数组)
摘要:可以用树状数组解决。先按左端点递增排序,左端点相等的按右端点降序排列。然后从左往有扫,更新答案同时更新sum数组。对于一只Cow i,ans[i]为f(i)-g(i).f(i)为满足p[j].s=p[i].e(0#include #include #include #include using na...
阅读全文
hdu 5050 Divided Land(JAVA高精度)
摘要:import java.util.Scanner;import java.math.BigInteger;public class Main { public static void main(String[] args) { Scanner cin=new Scanner(Sy...
阅读全文
hdu 5001 Walk(概率DP)
摘要:水水的#include #include #include #include #include #include using namespace std;int t,n,m,d;vectorg[55];bool w[55][55];double dp[2][55];double dfs(int x)...
阅读全文
hdu 5009 Paint Pearls (DP)
摘要:从前往后DP;先离散化;假设DP到第i个位置。las[i]表示第i种颜色最后一次出现的位置。t[k]表示满足w(t[i],i)==k的最小下标,w(a,b)表示从a,a+1,a+2......b这段区间的不同颜色的数量是多少。然后每次先更新t数组,再更新dp数组,k只需从1枚举到sqrt(n),所以...
阅读全文
hdu 4107 Gangster 线段树(成段更新)
摘要:维护每个区间的最小值和最大值,update的时候判断low[rt]与up[rt]和p的大小关系,进行更新操作。卡时卡得很紧。#include #include #include #include #include #define lson l,m,rtb)return a; return b;...
阅读全文
hdu 3037 Saving Beans (lucas定理)
摘要:考虑加多一颗树,这样的话当加的树放了k(0#include #include #include #include using namespace std;typedef long long ll;ll n,m,p;ll POW(ll x,ll n,ll p){ ll res=1; whi...
阅读全文
hdu 3944 DP? (Lucas 定理)
摘要:仔细观察杨辉三角后可以发现从最高点到第n行第k个数的最短路为c(n+1,k);根据Lucas定理可以求出,一般来说要求答案模去一个质数p且p的范围不大于10^5则可用Lucas.Lucas(n,m,p)=cm(n%p,m%p)* Lucas(n/p,m/p,p)Lucas(x,0,p)=1;另外注意...
阅读全文
hdu 5038 Grade 水
摘要:用map,也可以用数组,少了个特判WA了一发。#include #include #include #include #include #include #include using namespace std;const int maxn=1000005;int n;int a[maxn];int...
阅读全文
hdu 5023 A Corrupt Mayor's Performance Art (线段树)
摘要:把求和操作改为或操作,就可以了。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #define lson l,m,rt>1;27 build(lson);28 build(rson);29 up(r...
阅读全文
poj 1284 Primitive Roots(原根)
摘要:定理:假如一个数x有原根,则元根的个数为phi(phi(x)),phi(x)为小于x且与x互质的正整数个数。#include #include using namespace std;int p;int f(int x){ int ans=x; int m=sqrt(x+0.5); ...
阅读全文
UVALive - 3641 Leonardo's Notebook(polya计数)
摘要:题意:给出26个大写字母的置换B,问是否存在一个置换A,使A*A=B?两个长度为N的相同循环相乘,当N为奇数时结果也是一个长度为N的循环,当N为偶数时分裂为两个长度为N/2的循环。相反,对于一个任意长度为N的奇数循环B,都能找到一个长度为N的循环A使得A*A=B,对于任意两个长度为N(N不一定为偶数...
阅读全文
hdu 3869 Color the Simple Cycle (kmp+polya计数)
摘要:先把2*n个数字接成一个模式串P,复制两次的P为串T,然后在T上进行KMP找对P匹配的多个终点,然后就是用Polya定理了,需要求逆元。 1 #include 2 #include 3 #include 4 #include 5 #define mod 1000000007 6 using ...
阅读全文