![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
hdu
文章平均质量分 72
wxfwxf328
这个作者很懒,什么都没留下…
展开
-
HDU 3560 Graph’s Cycle Component 【并查集】
并查集分组,deg必需为2才是circle#include#includeusing namespace std;const int maxn=100000+10;int p[maxn],r[maxn],deg[maxn];bool is_circle[maxn];void init(int n){ memset(p,-1,n<<2); memset(r,0,n<原创 2012-02-13 22:13:18 · 1235 阅读 · 1 评论 -
HDU 3561 How many times 【计算几何】
判断任两圆的交点和每个圆的圆心即可#include#include#includeusing namespace std;#define eps 1e-8const int maxn=105;struct point{ double x,y;};struct circle{ point p; double r;}c[maxn];vectorv;原创 2012-02-13 22:07:43 · 840 阅读 · 0 评论 -
hdu 3555 Bomb【数位DP】
第一次接触数位DP#includeusing namespace std;long long dp[20][3]={0,1,0},d[20][3];int main(){ for(int i=1;i<20;i++) { dp[i][0]=10*dp[i-1][0]+dp[i-1][2];//含49 dp[i][1]=9*dp[i-1][1原创 2012-02-13 22:03:32 · 1010 阅读 · 0 评论 -
hdu 3524 Perfect Squares【打表、除法取余、快速幂】
先打表,找规律#include#includeusing namespace std;int main(){ setmyset; for(long long i=1;i<20;i++,cout<<endl) { myset.clear(); for(long long j=0;j<1000000;j++)原创 2012-02-10 17:24:36 · 1135 阅读 · 0 评论 -
hdu 3486 Interviewe 【RMQ】
不满足单调性,所以二分解法不正确(虽然可以过OJ),#include#includeusing namespace std;const int maxn=200000+10;int dp[maxn][20],mylog[maxn],n;long long k;void read(int &d){ char ch; while(ch=getchar(),ch57原创 2012-02-10 21:05:50 · 1337 阅读 · 1 评论 -
hdu 3547 DIY Cube【polya】
ans=17*x^2+6*x^4+x^8#include#include#includeusing namespace std;const int base=10000;const int width=4;const int N=1300;char s[1000];struct bint{ int ln,v[N]; bint(int r=0) {原创 2012-02-02 20:01:00 · 867 阅读 · 0 评论 -
poj 2002 Squares【HASH】POJ最快
先排序,然后枚举任意两点(x1,y1)(x2,y2),则如果存在点(x1+y1-y2,y1-x1+x2)(x2+y1-y2,y2-x1+x2)则它们能构成一个正方形157MS#include#include#include#includeusing namespace std;const int maxn=10000+10;struct node{ int a,b,c原创 2012-02-05 21:34:27 · 834 阅读 · 0 评论 -
hdu 3415 Max Sum of Max-K-sub-sequence【单调队列】
#include#includeusing namespace std;const int maxn=100000+10;int sum[maxn<<1],que[maxn<<1];void read(int &d){ char ch;bool flag=0; while(ch=getchar(),(ch>'9'||ch<'0')&&ch!='-'); ch==原创 2012-02-04 14:26:17 · 533 阅读 · 0 评论 -
HDU 3579 Hello Kiki【中国剩余】
#includeusing namespace std;typedef long long ll;ll ext_gcd(ll a,ll b,ll &x,ll &y){ if(b==0){x=1;y=0;return a;} ll d=ext_gcd(b,a%b,x,y),t; t=x;x=y;y=t-a/b*y; return d;}inline ll原创 2012-02-24 20:25:01 · 928 阅读 · 0 评论 -
poj2774 Long Long Message && hdu 1403 Longest Common Substring 最长公共字串【后缀数组(倍增)】
参考自2009年国家集训队论文《后缀数组——处理字符串的有力工具》(罗穗骞)将串a与串b连接后用后缀数组求最大height#include#includeusing namespace std;const int maxn=200000+10;int sa[maxn],rank[maxn],height[maxn],num[maxn];int wa[maxn],wb[max原创 2012-02-17 21:32:29 · 1374 阅读 · 1 评论 -
HDU 3589 Jacobi symbol 【二次剩余】
#include#includeusing namespace std;const int maxn=1000000+10;typedef long long ll;bool not_pri[maxn];int cnt=0,pri[maxn>>3];void init(){ for(int i=2;i<maxn;i++){ if(not_pri[i])原创 2012-03-02 18:07:51 · 909 阅读 · 0 评论 -
hdu 3400 Line belt【三分嵌套】
二分法作为分治中最常见的方法,适用于单调函数,逼近求解某点的值。但当函数是凸性函数时,二分法就无法适用,这时三分法就可以“大显身手”~~类似于二分的定义Left和Right,mid = (Left + Right) / 2,midmid = (mid + Right) / 2; 如果mid靠近极值点,则Right = midmid;否则(即midmid靠近极值点),则Left = mid;原创 2012-01-24 17:08:34 · 1136 阅读 · 3 评论 -
hdu 3663 Power Stations【DLX】
题意及分析来自:http://hi.baidu.com/z917912363/item/8ca932347e723ccd2f8ec269题意:给你一个最多60个点150个边的无向图,每个点是一个村庄,每个村庄都有一个发电站,每个电站可以给它所在的村庄和它有边直接连接的所有村庄供电,现在让你选出一些电站,使每个村庄都能被供电且每个村庄只被一个电站供电。另外,每个村庄的发电站都只能在1-d天内的一原创 2012-11-05 00:37:50 · 2322 阅读 · 0 评论 -
2012天津regional的五道水题(ABCEH)
做virtual judge时的代码,感觉有点挫,随便贴一下吧,继续切博弈。A题 模拟题这题本身还是非常水的。写的时候要注意题意,队友读的题意我写了很久调不出来,最后慢慢读题了才一个个错误地改出来了。#include #include #include #include #include #include using namespace std;mapmp;void原创 2012-10-28 23:55:35 · 4110 阅读 · 0 评论 -
hdu 3071 Gcd & Lcm game
一道还不错的题目,解法:线段树+位压缩对任意xint prime[]={ 2, 3, 5, 7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};int dpos[]={28,25,23,21,20,19,18,17,16,15,14,13,12,11,10, 9, 8, 7, 6, 5, 4, 3, 2原创 2012-04-20 03:48:07 · 1759 阅读 · 0 评论 -
poj 2893 hdu 3600 M*N数码问题
S = x0 + y0 + 逆序对个数(包含0)x0 y0指当前状态的0的坐标所以最终就是判断(初始的 x0 + y0 + 逆序对个数) %2 == ( m-1 + n-1 + m*n-1 )%2或者分奇偶性讨论亦可#include#include#includeusing namespace std;int a[1000000],_tmp[1000000];原创 2012-03-10 04:33:26 · 1248 阅读 · 0 评论 -
HDU 4167 User Names【string stl】
#include#include#include#includeusing namespace std;int main(){ cin.sync_with_stdio(false); int n,maxlen,cas=1; while(cin>>n>>maxlen) { if(n==0&&maxlen==0) break;原创 2012-03-03 18:30:49 · 1032 阅读 · 0 评论 -
hdu3584 Cube【三维树状数组】
详细见:http://wenku.baidu.com/view/2175f419ff00bed5b9f31db4.html 更新8个顶点就行了#include#include#includeusing namespace std;#define lowbit(x) x&-xconst int maxn=105;int n,m,a[maxn][maxn][maxn];v原创 2012-03-02 18:10:23 · 911 阅读 · 0 评论 -
hdu3590 PP and QQ 【ext_anti-nim】
anti-nim 博弈扩展(树形博弈)详细见:http://wenku.baidu.com/view/e0c822d3240c844769eaeea8.html#include#include#includeusing namespace std;int head[1000],nxt[1000],ev[1000];int edge=-1;int fa[2000];v原创 2012-03-02 18:13:23 · 973 阅读 · 0 评论 -
hdu 3549 Enumerate the Triangles
n^3暴力过了#include#include#includeusing namespace std;struct point{ double x,y;}p[1001];inline double dis(point a,point b){ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}int ma原创 2012-02-02 20:06:48 · 473 阅读 · 0 评论 -
hdu 3544 Alice's Game 【博弈】
后一人会尽量选前一人切后小的一块切。#includeusing namespace std;int main(){ int t,n,cas=1; long long a,b,x,y; cin>>t; while(t--) { cin>>n; a=b=0; for(int i=0;i<n;i++)原创 2012-02-02 19:42:19 · 1244 阅读 · 0 评论 -
hdu 1285 确定比赛名次 (浙大拓扑排序模板)
忘记了memset一下,WA了数次#includeusing namespace std;const int maxn=500+10;int map[maxn][maxn],p[maxn];int toposort(int n,int mat[][maxn],int *ret){ int d[maxn],i,j,k; for(i=0;i<n;i++) f原创 2012-01-20 22:02:17 · 1091 阅读 · 0 评论 -
hdu 3343 Legal or Not 拓扑排序(容易题)
#include#includeusing namespace std;const int maxn=100+5;int e[maxn];vectorv[maxn];void toposort(vector v[],const int n){ int flag=1,cnt=0; while(flag) { flag=0; for原创 2012-01-21 23:12:36 · 869 阅读 · 0 评论 -
hdu 3398 String 数论,catalon的一般形式(两次改进,比最初AC快了两倍)【完整版】
好难的题目啊,是cantalon数的一般情况啊,公式为c(a+b,b)-c(a+b,b-1),一开始想从cantalon推这一题,白浪费了一个小时,又是打了m,n的表和组合数的表,才推了这公式写完提交后无限WA,直到练习赛时间过了才想起来是我求的com(a+b, b)-com(a+b,b-1)可能为负值,因为a>b不代表a%p>b%p,即(a-b)%p = ((a%p-b%p)+p)%p而原创 2012-01-21 20:14:56 · 3002 阅读 · 1 评论 -
HDU 3307 Description has only two Sentences 数论
Description has only two SentencesTime Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 199 Accepted Submission(s): 9Problem Descrip原创 2012-01-21 19:59:02 · 1108 阅读 · 0 评论 -
HDU 3314 Trouble with Election! 并查集
这题想通了就好做了,只有投了自己的人才可能是最后的WINNER,找符合的人中最大值是不是唯一#includeusing namespace std;const int maxn=100000+10;int p[maxn],r[maxn],cnt[maxn];void make(){ memset(r,0,sizeof(r)); memset(p,255,sizeof(原创 2012-01-21 19:29:42 · 630 阅读 · 0 评论 -
hdu 3306 Another kind of Fibonacci
As we all known , the Fibonacci series : F(0) = 1, F(1) = 1, F(N) = F(N - 1) + F(N - 2) (N >= 2).Now we define another kind of Fibonacci : A(0) = 1 , A(1) = 1 , A(N) = X * A(N - 1) + Y * A(N - 2) (N >原创 2012-01-21 19:20:32 · 561 阅读 · 0 评论 -
hdu 3790 最短路径问题 【双权值最短路(相同最小距离,求最小花费)】
//注释为CIN/COUT版,cin.sync_with_stdio(false)一定要有,不然会超时#includeusing namespace std;const int maxn=1000+10; //点数const int maxm=1000000+10; //边数const int inf=0x3f3f3f3f;typedef pair elem_t;inlin原创 2012-01-20 15:25:36 · 2153 阅读 · 0 评论 -
hdu 2112 HDU Today 字典树+Dijkstra
#include#include#include#define th(a) this->a=ausing namespace std;const int maxn=150+10;const int inf=0x3f3f3f3f;struct trie_t{ int lnk[64],val; void init() { memset(lnk,0,原创 2012-01-20 15:40:02 · 456 阅读 · 0 评论 -
hdu 2647 Reward 拓扑排序
http://acm.hdu.edu.cn/showproblem.php?pid=2647#include#include#includeusing namespace std;const int maxn=10000+5;paire[maxn];//first:入度 second:工资(最低为0)void toposort(vector v[],const int n){原创 2012-01-21 01:38:59 · 772 阅读 · 0 评论 -
hdu 1231最大连续子序列 【DP】
//dp[i] = max(dp[i-1]+a[i],dp[i]) = a[i]+dp[i-1]<0?0:dp[i-1];//max=a[i]+max<0?0:max;#includeusing namespace std;int a[10010];inline void read(int &d){ char ch; int flag=1; while(ch=g原创 2012-01-25 12:46:21 · 619 阅读 · 0 评论 -
poj 2559 hdu 1506 Largest Rectangle in a Histogram
#includeusing namespace std;const int maxn=100000+10;int a[maxn],b[maxn],c[maxn];//a[i]:高度 b[i]:左边小于a[i]高度的第一个 c[i]:右边小于a[i]高度第一个inline void read(int &d){ char ch; while(ch=getchar(),ch>原创 2012-01-25 14:38:29 · 796 阅读 · 0 评论 -
hdu 3549 Flow Problem【最大流】
直接模板#includeusing namespace std;const int maxn=20;const int inf=0x3f3f3f3f;struct EK{ int cap[maxn][maxn]; int flow[maxn][maxn]; int n; void init(int n) { this->n=n原创 2012-02-02 20:03:18 · 522 阅读 · 0 评论 -
hdu 3552 I can do it!
sort对X排序, ans=min(x[i]+max(y[i+1]+y[i+2]+……) ) (i=n,n-1,……2,1);以i从大到小的顺序扫描一下o(n);#include#include#includeusing namespace std;struct node{ int x,y;}a[100010];bool cmp(node a,node b){原创 2012-02-02 19:49:31 · 685 阅读 · 0 评论 -
hdu 3546 Calculator
若c=b,则之前的C不要求,直到遇到更前面有a=c或a*=c或a+=c时,C的值才要计算#include#include#includeusing namespace std;const int base=10000;const int width=4;const int N=1300;struct bint{ int ln,v[N]; bint(int r=0原创 2012-02-02 19:58:02 · 757 阅读 · 0 评论 -
hdu 2955 Robberies 【dp】 01背包
#includeusing namespace std;const int maxn=10000+10;int m[maxn];double p[maxn],dp[maxn];int main(){ int t,n,sum; double p0; cin.sync_with_stdio(false); cin>>t; while(t--)原创 2012-01-25 12:03:18 · 541 阅读 · 0 评论 -
hdu 1864 最大报销额 【DP】
#include#includeusing namespace std;const int maxn=3000000+10;int dp[maxn],v[100];int main(){ int n,m,cnt; double a[3],q; while(cin>>q>>n&&n) { cnt=0; while(n--)原创 2012-01-25 12:04:43 · 705 阅读 · 0 评论 -
hdu 1003 Max Sum【DP】 0MS 248K
//dp[i] = max(dp[i-1]+a[i],dp[i]) = a[i]+dp[i-1]<0?0:dp[i-1];//max=a[i]+max<0?0:max;#includeusing namespace std;inline void read(int &d){ char ch; int flag=1; while(ch=getchar(),ch=='原创 2012-01-25 13:15:29 · 810 阅读 · 2 评论 -
hdu 1811 rank of tetras 拓扑排序+并查集
这题写了几天了,好几次写了一半又删了的,发现拓扑还是用queue好啊1.3种结果的优先关系conflict>uncertain>ok,只要是conflict就不是看后两者了,如果不是只有判了是uncertain就不看是否ok了,用solve()函数返回结果的情况2.q.size()>1,同时多个点入度为0,uncertain.(要=判断了conflict才确定) 入q次数与n'不等则原创 2012-01-23 13:53:16 · 727 阅读 · 0 评论 -
HDU 1695 GCD 数论好题!
http://acm.hdu.edu.cn/showproblem.php?pid=1695此题思路基本分析出来了,可是写错来WA到不认识家了,果断删了自己代码,参考了别人的代码写的:参考自:http://blog.csdn.net/shiren_bod/article/details/5787722#quote(这个初始化写得好比较好了,一开始自己写用了写了两个函数一个求euler+原创 2012-01-25 17:16:16 · 1137 阅读 · 0 评论