acm
zhoutonglx
用汗水与泪水去追逐光荣与梦想,亦感受怅然与失落
展开
-
hdu1251 统计难题 字典树
字典树模板题#include#includeusing namespace std;struct point{ point* next[26]; int cot; point() { cot = 0; memset(next,0,sizeof(next)); }};void原创 2015-10-18 11:02:57 · 331 阅读 · 0 评论 -
poj 2352
看了别人的题解,终于对树状数组有所了解了#include#include#includeusing namespace std;const int MAX=32005;int lowbit(int x){ return x&(-x);}int level[322005];int bit[32005];int sum(int x){ int ran原创 2015-02-03 20:10:11 · 321 阅读 · 0 评论 -
poj 2431 Expedition 优先队列 大顶堆
这题书上说要优先队列,然后看了一下,试着敲了一下,一敲就是这么久#include#include#includeusing namespace std;int b[100020];int c[100020];struct point{ int d; int c; friend bool operator<(point a,point b)原创 2015-07-28 20:45:58 · 301 阅读 · 0 评论 -
poj 1122 FDNY to the Rescue! 最短路径 dijkstra算法
这道题做了好多发,用sscanf()读入提交老是RE,不知道为甚么,谁能帮我解决下,后来改用isstringstream就ac了。sscanf() RE,大牛帮我看一下 gets(s); gets(s); int k=0; i=0; int len=strlen(s); while(s[i]==' ') i++; while(i<原创 2015-07-27 15:33:41 · 281 阅读 · 0 评论 -
hdu 2087 减花布条 kmp
#include#includeusing namespace std;char s1[1000005];char s2[1005];int p[10005];int l1,l2;void init(){ int i,j; i=0; l2 = strlen(s2); j=-1; p[0]=-1; while(i<l2) {原创 2015-07-12 13:05:29 · 277 阅读 · 0 评论 -
poj PIGS 网络流EK
这尼玛都能过,太高兴了,意料之外图建得惨不忍赌啊#include#include#include#includeusing namespace std;const int inf = 0x7f7f7f7f;int a[1100];int p[405][405];int pre[405];int maxflow=0;queueq;int sp,sf;int vis[原创 2015-07-26 10:29:44 · 320 阅读 · 0 评论 -
poj 2752 Seek the Name, Seek the Fame
总算对kmp有一点点了解了next[j]表示1~j和j~i的字符相等,并且j!=i;#include#includeusing namespace std;char s[400004];int len;int p[400004];int c[400004];void init(){ int i,j; i=0; j=-1; p[0]=原创 2015-07-11 09:44:23 · 303 阅读 · 0 评论 -
poj 1459 Power Network 网络流 ek算法
这道题做的我好心酸啊,一直T,原来把算法搞错了,需要一个数组记录路径中的流量,而我就是用一个增量保存,所以其他路径上的最小值也会改变当前路径的最小值,因此一直t吸取教训了#include#include#include#includeusing namespace std;const int inf = 0x3f3f3f3f;struct point { i原创 2015-07-25 15:26:48 · 413 阅读 · 0 评论 -
hdu 3746 Cyclic Nacklace (kmp算法)
求周期串,从末尾开始观察是否有周期串,没有就加一个和p[i]+1相等的字符,直到出现周期串#include#include#include#include#includeusing namespace std;string a;int len;int p[100005];int init(){ int i,j; i=0; j=-1;原创 2015-07-12 15:51:25 · 251 阅读 · 0 评论 -
poj 3320 尺取法
这道题,用std::ios::sync_with_stdio(false);都超时,非得用scanf();#include#include#include#include#includeusing namespace std;int a[1000002];sets;mapmp;int main(){ int n; scanf("%d",&n); int i,原创 2015-06-03 16:39:07 · 303 阅读 · 0 评论 -
poj 3279 Fliptile 再关灯
#include#include#includeusing namespace std;int a[18][18];int b[20][20];int c[20][20];int dx[]={1,0,-1,0,0};int dy[]={0,1,0,-1,0};int n,m;int get(int x,int y){ int i; int d=a[x][y]; i原创 2015-06-04 11:59:47 · 360 阅读 · 0 评论 -
hdu 5248
正在做二分,还是被二分虐啊#include#includeusing namespace std;int a[100005];int b[100005];int main(){ std::ios::sync_with_stdio(false); int t; cin>>t; int kase; for(kase=1;kase<=t;kase++) { int n;原创 2015-06-03 15:59:24 · 340 阅读 · 0 评论 -
poj 2785 4 Values whose Sum is 0
这道题,让我明白了lower_bound(),upper_bound()的威力啊#include#include#includeusing namespace std;int a[4003];int b[4003];int c[4003];int d[4003];int e[16000003];int main(){ int n; cin>>n; int i原创 2015-06-04 12:30:54 · 303 阅读 · 0 评论 -
poj 3276 Face The Right Way 关灯问题
#include#includeusing namespace std;int d[50005];int f[50005];int n;int solve(int k){ memset(f,0,sizeof(f)); int res=0; int sum=0; int ans=0; int i; for(i=0;i+k<=n;i++) { if((sum+d[i]原创 2015-06-03 17:48:03 · 397 阅读 · 0 评论 -
poj 2236Wireless Network 并查集
好久没写过并查集了,居然1A,纪念一下#include#includeusing namespace std;int n,m;struct point{ int x,y;}p[1002];int vis[30030];int fa[300000];int findd(int x){ int s; for(s = x;s!=fa[s];s=f原创 2015-08-09 20:27:00 · 341 阅读 · 0 评论 -
poj 3468 A Simple Problem with Integers 线段树
#include#include#includeusing namespace std;typedef long long ll;struct point { long long l; long long r; long long w; long long m;}p[400002];void init(ll l,ll r,ll k){原创 2015-07-16 19:24:16 · 280 阅读 · 0 评论 -
POJ 2299 Ultra-QuickSort 树状数组,归并排序
我用归并排序做的,树状数组,想通了,再写。#include#includeusing namespace std;int n;int a[500003];int b[500003];long long sum;void merge(int l,int m,int r){ int k; int tmp=l; int j; int i;原创 2015-07-16 12:13:09 · 291 阅读 · 0 评论 -
Counting Sort
As for counting sort,we need to know the range of value of the array.It can not be too large. Than we count how many times the element comes. At last, we start from 0 to max value as i, if count[i] is原创 2016-07-28 00:49:14 · 252 阅读 · 0 评论 -
hdu2795 Billboard 线段树
好久没做线段树,都忘得差不多了,来一发#includeusing namespace std;struct point{ int l,r,w;}p[600010];int w;void init(int l,int r,int k){ p[k].l = l; p[k].r = r; p[k].w = w; if(l==r)原创 2015-10-08 19:48:49 · 343 阅读 · 0 评论 -
hdu 5444 Elven Postman
题目要求我们建立一棵二叉搜索树,然后每次从根出发,走的路径记录下来数据结构#includeusing namespace std;struct point{ int v; point * lson; point * rson;};point *root=NULL;int k;char path[10010];void searchB原创 2015-09-16 14:01:25 · 323 阅读 · 0 评论 -
poj 1463 Strategic game 树形dp
第一个自己做出来的树形DP,nice.#include#includeusing namespace std;int a[10010];int n;struct point{ int son; int father; int brother; int put; int not_put;}p[10010];void init(){原创 2015-09-10 18:37:09 · 322 阅读 · 0 评论 -
hdu 1114 Piggy-Bank 完全背包
完全背包 对每个银币进行完全背包#includeusing namespace std;int w[100010];int v[100010];int dp[100010];const int inf = 0x3f3f3f3f;void completepack(int v,int w,int sum){ int i; for(i=0;i<=sum原创 2015-09-03 16:17:45 · 292 阅读 · 0 评论 -
poj 1840 Eqs 哈希散列
哈希的一血#include#include#includeusing std::cout;using std::endl;const int mod = 139997;int hash[140000];int cot=0;int a[140000][100];inline void insert(int ans){ int he = (ans%mod+m原创 2015-08-05 13:41:34 · 313 阅读 · 0 评论 -
poj 2689 Prime Distance 筛素数加强版
这题敲得我好感人啊,踌躇了几天,终于干掉它了#include#include#includeusing namespace std;typedef long long ll;ll l,u;ll a[50010];ll b[50010];ll c[1000100];ll d[1000100];ll k = 0;void init(){ ll i,j;原创 2015-08-16 20:10:37 · 502 阅读 · 0 评论 -
poj 2142 The Balance 数论-扩展欧几里得
扩展欧几里得算法应用#includeusing namespace std;int x,y,d;int exgcd(int a,int b,int &x,int &y){ if(b == 0) { x = 1; y = 0; return a; } int d = exgcd(b,a%b,y,x);原创 2015-08-15 12:56:49 · 368 阅读 · 0 评论 -
poj 3258 River Hopscotch二分
二分从来都没有把握,这次居然1A,纪念一下#include#include#includeusing namespace std;int a[50005]{0};int b[50005]{0};int main(){ std::ios::sync_with_stdio(false); int l,n,m; cin>>l>>n>>m; a[原创 2015-07-23 09:53:51 · 259 阅读 · 0 评论 -
hdu 2444The Accomodation of Students 二分图判定+找最大匹配
#includeusing namespace std;int t;int link[100010];bool vis[100010];int n,m;int color[100010];vectorv[100101];bool dfs(int x){ int i,j; vis[x]=1; for(i=0;i<v[x].size();i++) {原创 2015-07-20 16:02:32 · 411 阅读 · 0 评论 -
hdu 3549 Flow Problem ek算法,网络流
啊,第一滴血,网络流#includeusing namespace std;const int inf = 0x3f3f3f3f;struct point{ int c; int f;}a[18][18];vector v[20];queue q;int n,m;int vis[25];int maxflow;int pre[25];int a原创 2015-07-19 19:10:02 · 303 阅读 · 0 评论 -
hdu 3333 Turing Tree 树状数组
这道题和 hdu 3874 几乎一模一样#include#include#include#includeusing namespace std;typedef long long ll;ll a[30002];ll sum[300003];ll ans[130000];mapmp;const long long int N = 300000;struc原创 2015-07-17 18:45:45 · 320 阅读 · 0 评论 -
poj 1195 Mobile phones 二维树状数组
二维数组在就和(a,b),(c,d) :a getsum(c,d)+getsum(a-1,b-1)-getsum(a-1,d)-getsum(c,b-1)#include#includeusing namespace std;typedef long long ll;ll sum[1140][1140];ll size;void init(ll x){原创 2015-07-17 20:51:54 · 267 阅读 · 0 评论 -
poj 3061
前缀和,再二分lower_bound()返回数组的所要找的值,找完所有都找到,则返回下一位,如果所有的都比当前小,返回第一位,(数据结构二叉堆)#include#include#include#includeusing namespace std;int a[100003];int sum[100003];int main(){ int t; cin>>t;原创 2015-05-28 14:14:42 · 345 阅读 · 0 评论 -
poj 2456
二分再来一发#include#includeusing namespace std;int n,m;int a[100005];int solve(int x){ int cot=0; int i; int pos=a[0]; for(i=0;i<n;i++) { if(a[i]-pos>=x) { cot++; pos=a[i]; } i原创 2015-05-28 10:53:15 · 398 阅读 · 0 评论 -
poj 1064
二分题,不解释#include#include#include#includeusing namespace std; int n,m;double a[10005];int solve(double x){ int i,j; int sum=0; for(i=0;i<n;i++) { sum+=int(a[i]/x); } return sum;}原创 2015-05-27 14:46:45 · 292 阅读 · 0 评论 -
hdu 1232 并查集
好久没动过并查集,居然错了这么多次//union_find_set#includeusing namespace std;int n,m;int fa[10002]; void init(){ int i; for(i=0;i<=n;i++) { fa[i]=i; } return ;}int findd(int x){ int s; for(s=x;s原创 2015-03-10 18:24:16 · 251 阅读 · 0 评论 -
zoj 3326
神坑模拟,这种题,没意思#includeusing namespace std;int sum=0;bool prime(int x){ int i; if(x==1) return 0; for(i=2;i*i<=x;i++) { if(x%i==0) return 0; } return 1;}bool leap(int x){ if原创 2015-03-21 11:51:56 · 415 阅读 · 0 评论 -
zoj 3623 battle ships
这条题有点意思,虽然我不会#includeusing namespace std;int t[800];int l[800];int dp[800];int main(){ int n,m; while(cin>>n>>m) { memset(dp,0,sizeof(dp)); int i,j,k; for(i=1;i<=n;i++) { ci原创 2015-03-20 20:11:00 · 349 阅读 · 0 评论 -
hdu 3555
我的第一个数位dp题终于做了一发数位dp的题,有点模糊,是照着别人的题解敲的#includeusing namespace std;long long bit[22];long long dp[22][3];void init(){ memset(dp,0,sizeof(dp)); dp[0][2]=1; for(int i=1;i<20;i原创 2015-03-26 15:31:48 · 335 阅读 · 0 评论 -
hdu 1223 minimum spanning tree
用kruskal 来了一发,卧槽,排序的时候把边的数目和点的数目搞混了,又wrong了#includeusing namespace std;int cot;int n;int sum;struct edge{ int x; int y; int w;}a[100005];int fa[1056];void init(){ int i; for(i=1原创 2015-03-12 11:11:00 · 424 阅读 · 0 评论 -
dfs
http://codeforces.com/contest/510/problem/B#includeusing namespace std;int n,m;int ok;char edge[52][52];int vis[52][52];int stat[52][52];int dir[][2]={{1,0},{0,1},{-1,0},{0,-1}};void dfs(i原创 2015-02-24 22:00:54 · 266 阅读 · 0 评论 -
hdu 3466
这种变种的01背包,不看题解,就想不到状态转移的方程啊,看了题解又觉得有道理这背包要sort一下,要求的价格减去实际的价格从小到大排序,状态转移时才能确保没有后效性。#include#include#include#includeusing namespace std;struct p{ int p; int ep; int w;}a[505];bool原创 2015-02-18 13:10:25 · 374 阅读 · 0 评论