01 2014 档案
乘法逆元
摘要:d模f的乘法逆元int Extend_Eulid(int d,int f){ int x1,x2,x3,y1,y2,y3 ; x1=1,x2=0,x3=f,y1=0,y2=1,y3=d ; while(y3 && y3!=1) { int q=x3/y3 ; int t1,t2,t3 ; t1=x1-q*y1,t2=x2-q*y2,t3=x3-q*y3 ; x1=y1,x2=y2,x3=y3 ; y1=t1,y2=t2,y3=t3 ; } if(!y3)return -1 ; ret...
阅读全文
HDU 1452
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1452原来真心没见过这种题,不会做,非常帅gcd(a,b)==1 && s(a,b)==s(a)*s(b)满足这种条件的s叫做积性函数,本题求的因子和就是一个积性函数接着有一个结论if(prime[p])s(p^n)=1+p^1+p^2+p^n=(p^(n+1)-1)/(p-1)s(2004^n)=s(2^(2n))*s(3^n)*s(167^n)其中,167和22关于29同余所以,s(2004^n)=s(2^(2n))*s(3^n)*s(2^n)a=s(2^(2n))=(2^(2n+1)-1
阅读全文
HDU 2665
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2665在线询问静态区间k大去学主席树,没看懂;学树套树,没看懂;最后划分树拯救了我,orz......划分树讲解看百度百科#include #include using namespace std ;int tree[30][100005] ;int toleft[30][100005] ;int sorted[100005] ; void build(int l,int r,int dep){ if(l==r)return ; int m=(l+r)>>1 ; int same=m-l+1...
阅读全文
HDU 1806
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1806非常玄妙的rmq问题,这个st算法有点神#include #include using namespace std ;int dp[100005][20] ;int a[100005],b[100005] ;void makermq(int n,int *tt){ for(int i=0 ;i>1 ; if(a[mid]>temp) r=mid-1 ; else if(a[mid]=0 ;i--) { if(i=...
阅读全文
HDU 1043
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1043http://www.cnblogs.com/goodness/archive/2010/05/04/1727141.html根据这篇文章说的八数码八境界,我这种做法大概是在境界三。。我选择的是康托展开作为哈希函数,在全排列问题中这个哈希函数可以很好的处理冲突http://zh.wikipedia.org/zh/%E5%BA%B7%E6%89%98%E5%B1%95%E5%BC%80当然白书上的那种哈希也是极好的。。#include #include #include using namespace s
阅读全文
HDU 1073
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1073模拟oj判题随便搞,开始字符串读入的细节地方没处理好,wa了好久#include #include #include #include using namespace std ; char s1[100005...
阅读全文
CF 382C
摘要:http://codeforces.com/problemset/problem/382/C读完题立刻知道怎么做,然后分类讨论到吐血,写挂了,巨蠢#include #include #include #include using namespace std ;int n ;int a[100005] ;int temp1,temp2 ;int cnt1,cnt2,p1,p2 ;int gao(){ int f=1 ; cnt1=cnt2=0 ; temp1=a[0]-a[1] ; for(int i=1 ;i=1 ;i--) if(a[i]-a[i-1]!...
阅读全文
两个二分
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4190二分答案#include using namespace std ;int a[500005] ;int main(){ int n,b ; while(~scanf("%d%d",&n,&b),n!=-1) { int maxn=-1 ; for(int i=0 ;i>1 ; int sum=0 ; for(int i=0 ;ib) left=mid+1 ; e...
阅读全文
为什么总因为傻逼的错误葬送大好的局势
摘要:弱者到底为何战斗——构造一组数据,看我cha遍全场
阅读全文
HDU 3378
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3378规则去玩三国杀就理解了纯模拟注意的点:有已经分出胜负但还在杀的情况出现,所以要每次杀操作前判断是否分出胜负,如果已经分出胜负了就continue,不用接着往下操作#include #include #include using namespace std ;int n ;typedef struct L{ char js[5] ; int al ; int esc ; int sc ;}L ;L kk[101] ;int pk ;int bjnj,wnj ;int ok(){ ...
阅读全文
|