
ACM
文章平均质量分 59
X-Wyatt
For free 邮箱whitezhangv5@gmail.com
展开
-
HDU 1035
搜索,就这样了。第一次多输出了点东西结果WA了#include #include #include using namespace std;#define LEN 11int map[LEN][LEN];int point[][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};int row, col;void find(int x, in原创 2012-12-05 19:51:20 · 424 阅读 · 0 评论 -
HDU 1087
恶心到我的一道水题,没有1A的原因是我把两个long long 数组都申请了栈空间。#include #include #include using namespace std;long long num[1001];int main() { int n; long long ans[1001]; while(scanf("%d", &n)&&n)原创 2012-11-01 19:50:33 · 367 阅读 · 0 评论 -
HDU 2419
我原先的代码,一开始超空间,后来用vector后还是超时了#include #include #include #include using namespace std;#define MMAX 9999999#define LEN 20010//bool map[LEN][LEN];vector map[LEN];int vertex[LEN];int p[LEN]原创 2012-09-21 21:23:12 · 767 阅读 · 0 评论 -
HDU 1892
二维树状数组,和一维的基本差不多,只需要把update和query函数扩展为二维就行了#include #include #include using namespace std;#define LEN 1002#define MIN(a,b) (a<b?a:b)int tree[LEN+1][LEN+1];int lowbit(int x) { return原创 2012-09-15 14:11:30 · 838 阅读 · 0 评论 -
HDU 1754
线段树的模板题。buildTree, insert, update, query 四个函数写的时候注意叶子节点,左右孩子就行了#include #include #define LEN 400400#define NMAX -999999typedef struct Node { int l, r; struct Node* lChild; st原创 2012-09-13 15:03:41 · 390 阅读 · 0 评论 -
Codeforces-125D2A
Brute force problem and it is very easy.My code is as follows:#include #include using namespace std;#define LEN 101long long fib[LEN];void init() { fib[0] = 0; fib[1] = 1; for(in原创 2012-09-12 08:52:19 · 387 阅读 · 0 评论 -
HDU 1210
一个似曾相识的题。以前的是找规律然后找所有周期的最小公倍数#include #include int main() { int n,t,k,s; while(scanf("%d",&n)!=EOF) { t=1,s=0; while(1) { if(t<=n)原创 2012-11-27 01:58:18 · 796 阅读 · 0 评论 -
HDU 1085
分类就可以了#include #include #include using namespace std;int main() { int a, b, c; while(scanf("%d%d%d", &a, &b, &c), !(0 == a && 0 == b && 0 == c)) { int i, j, sum; sum = 0; if(a >= 2 &&原创 2012-11-01 20:52:49 · 370 阅读 · 0 评论 -
HDU 3293
字符串的排序模拟:以后最好都用 qsort。这里用sort排序出来的结果不对。sort 是用大于小于号来返回bool值进行排序。qsort 则返回int类型,从而进行排序PS:升序用后一个减去前一个#include #include #include #include using namespace std;struct Weapon { char name[21]原创 2012-10-31 15:25:58 · 467 阅读 · 0 评论 -
HDU 4296
看了别人的报告才写出来的证明:对于相邻放置的两块板,设两块板为i,j他们上面的重量为sum 1) a=sum-si;b=sum+wi-sj; 交换两个板的位置 2)a'=sum+wj-si;b'=sum-sj; 如果1优于2,求解得有效的条件为wj-si>wi-sj。原创 2012-09-18 22:21:05 · 432 阅读 · 0 评论 -
Codeforces143Div.2-B
Simulated problem:#include #include #include #include using namespace std;#define LEN 100001int a[LEN], su[LEN];int main() { int n, k; while(scanf("%d%d", &n, &k) != EOF) { int i, j原创 2012-10-10 01:13:37 · 1001 阅读 · 0 评论 -
Codeforces140Div.2
a.cc#include #include using namespace std;int main() { long long xa, xb, xc; long long ya, yb, yc; long long i, j; cin>> xa>> ya>> xb>> yb>> xc>> yc; if((yb-ya)*(xc-xb) == (yc-yb)*(xb-x原创 2012-10-02 17:14:22 · 420 阅读 · 0 评论 -
HDU 1856
简单题,直接代码了#include #include #include using namespace std;#define LEN 10000002int p[LEN];int len[LEN];void init() { int i; for(i = 1; i < LEN; i++) { p[i] = i; }}int find(int x) { re原创 2012-09-21 16:15:22 · 388 阅读 · 0 评论 -
HDU 1394
第一次提交的代码果断TLE了,代码如下#include #include #include using namespace std;#define LEN 5005int in[LEN], tree[LEN];int lowbit(int x) { return x & (-x);}void update(int x) { while(x <= LEN)原创 2012-09-15 23:12:28 · 422 阅读 · 0 评论 -
HDU 2689
求逆序对个数,其实就和之前写的那个题差不多,很简单,直接贴代码了。PS:树状数组可以用来求有大小关系的区间#include #include #include using namespace std;#define LEN 1001int tree[LEN+1], in[LEN+1];int ans[LEN+1];int lowbit(int x) { re原创 2012-09-15 21:23:47 · 555 阅读 · 0 评论 -
HDU 1166
单点更新,求区间#include #include #define LEN 50001int a[LEN];int c[LEN];int lowbit(int x) { return x & (-x);}void update(int pos, int val) { while(pos <= LEN) { c[pos] += val;原创 2012-09-14 21:56:12 · 440 阅读 · 0 评论 -
Codeforces134Div.2-C
用并查集,没有用搜索的方式。中途犯了一点小错误#include #include #include using namespace std;#define LEN 1010int p[LEN], x[LEN], y[LEN];void init() { int i; for(i = 0; i < LEN; i++) { p[i] = i; }}int f原创 2012-10-05 17:30:28 · 659 阅读 · 0 评论 -
鸽巢原理以及Ramsey定理详解
简单形式:定理:如果有n+1个物体被放进n个盒子,那么至少有一个和紫包含两个或者更多的物体。 定理非常的简单,但是真正用好这个定理却需要一定的功底。eg1.以为国际象棋大师有11周的时间备战一场锦标赛,他决定每天至少下一盘国际象棋,但是为了不使自己过于疲劳,他还决定在每周不能下超过12盘。证明存在连续若干天,期间这位大师恰好下了21盘棋。证明:鸽巢原理的应用最终就是要找到物原创 2012-11-10 21:53:15 · 7044 阅读 · 4 评论 -
Project Euler-6
Problem:The sum of the squares of the first ten natural numbers is,12 + 22 + ... + 102 = 385The square of the sum of the first ten natural numbers is,(1 + 2 + ... + 10)2 = 552 = 3025He原创 2012-09-11 21:05:07 · 381 阅读 · 0 评论 -
Project Euler-5
Problem:2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.What is the smallest positive number that is evenly divisible by all of the nu原创 2012-09-11 20:45:55 · 435 阅读 · 0 评论 -
Project Euler-3(素数问题)
Problem:The prime factors of 13195 are 5, 7, 13 and 29.What is the largest prime factor of the number 600851475143 ?I print the prime number first and my codes are as follows:#includ原创 2012-09-11 19:00:26 · 508 阅读 · 0 评论 -
HDU 4268
一开始写的代码一直TLE,我的方法是n^2的二重循环。看完别人的解体报告后才发现了另一种更好的办法把两个数组放在一块,然后排序,从而保证了后面的必能覆盖了前面的,把时间复杂度降到了2n #include #include #include #include #include #define LEN 100001#define MMAX 999999using nam原创 2012-12-01 00:12:59 · 565 阅读 · 0 评论 -
HDU 1033
模拟水题,题意就是起始点为(300,420),然后每次根据现有的方向移动10个unit,依次输出PS:最近在刷第一页#include #include #include using namespace std;#define LEN 300int main() { char cmd[LEN]; while(scanf("%s", cmd) != EOF) { int原创 2012-12-05 17:14:44 · 1250 阅读 · 0 评论 -
HDU 2896
#include#include#include#includeusing namespace std;const int maxn = 100008;int sz, ans[8];int arr[maxn], mark[maxn];char ch[508][208];char txt[10008];struct Node{ int count, f原创 2012-10-02 14:45:44 · 435 阅读 · 0 评论 -
KMP算法总结
KMP题目重在理解next数组的含义:next数组的作用 :next[j] 记录模式串中第 j 个字符的最长公共前缀长度(重要,这是它的意义所在) 第二种理解方式,当模式串与主串失配时,跳回的位置。next[len] (即字符串'\0'结束标志的next值):单个字符串匹配时与周期有关原创 2012-09-11 18:48:19 · 448 阅读 · 0 评论 -
HDU 1213
并查集的复习水题#include #include using namespace std;#define LEN 10000int p[LEN];void init(int n) { int i; for(i = 1; i <= n; i++) { p[i] = i; }}int find(int x) { return p[x] == x ? x : (原创 2012-09-20 15:34:40 · 464 阅读 · 0 评论 -
HDU 2492
挺巧的一道题,笨的办法就是暴力搜索,但是用树状数组可以很巧妙的解决。这题实质上就是每次 update 更新 val+1,然后求每段区间的长度。#include #include #include using namespace std;#define LEN 100002int tree[LEN+2];int in[LEN+2];int lmin[LEN+2],原创 2012-09-15 20:44:01 · 515 阅读 · 0 评论 -
HDU 1541
树状数组的应用,只是利用的它向后更新,向前查询的性质。#include #include #define LEN 150001int tree[LEN];int level[LEN];int lowbit(int x) { return x & (-x); }void update(int pos) { while(pos <= LEN) {原创 2012-09-14 23:20:59 · 461 阅读 · 0 评论 -
HDU 1016
好久没写搜索了,差不多要不会了。看了下滔滔的解题报告才写出来的。http://blog.youkuaiyun.com/chuck_0430/article/details/8127339深搜的核心也就是 vis 标志数组的改变,并在中间递归调用 dfs#include #include #include #define NUMBER 500000 #define LEN 10000原创 2012-11-05 21:16:20 · 517 阅读 · 0 评论 -
Codeforces-134D2A
Easy problem and I directly attached to the code.#include #include using namespace std;#define LEN 1000int mon[LEN];int index[LEN];int main() { int n, k, tmp; int i, count; scanf("原创 2012-09-13 15:54:12 · 411 阅读 · 0 评论 -
UVa 10303
catalan数:令h(0)=1,h(1)=1,catalan数满足递推式h(n)= h(0)*h(n-1)+h(1)*h(n-2) + ... + h(n-1)h(0) (n>=2) 例如:h(2)=h(0)*h(1)+h(1)*h(0)=1*1+1*1=2 h(3)=h(0)*h(2)+h(1)*h(1)+h(2)*h(0)=1*2+1*1+2*1=5 另类递推式原创 2012-10-11 01:52:15 · 574 阅读 · 0 评论 -
HDU 1789
主要是一个思路:按照 reduced socres 从大到小排序, deadline 从大到小或者从小到大都可以。假设这里的deadline是从小到大的例如有这样一组数据1 2 2 4 4 45 2 4 5 5 5排序完之后:首先安排 reduced为5的,第一天就有事情做了,然后查找到第四天的,随后第四天也有事情做了,再次查找,发现第四天有事情做了,所以推到第三天,同理下一个推原创 2012-11-09 22:19:04 · 615 阅读 · 0 评论 -
HDU 1051
1A, Greedy algorithm:#include #include #include #include using namespace std;#define LEN 5010typedef struct Node{ int l, w;}Node;Node node[LEN];Node ans[LEN];int cmp(Node a, Node b) {原创 2012-10-08 17:38:16 · 545 阅读 · 0 评论 -
UVa 111
第二次刷这个题了,动归,空间上从原来的 n^2 到现在的 2n,做了优化PS:原来的代码找不到了,从网上download了一个,思想是一样的#includeusing namespace std;const int MAXN = 30;int aim[MAXN], now[MAXN], f[MAXN][MAXN];int max(int x, int y) {return (x >原创 2012-12-06 01:46:50 · 395 阅读 · 0 评论 -
HDU 1232
并查集水题:#include #include #define LEN 1001int p[LEN];void init(int len) { for(int i = 0; i <= len; i++) { p[i] = i; }}int find(int x) { return p[x] == x ? x : (p[x] = find(p[x]));}in原创 2012-11-26 17:52:22 · 965 阅读 · 0 评论 -
HDU 2642
和前一个二维树状数组基本一样,果断1A#include #include #include using namespace std;#define LEN 1002int tree[LEN+2][LEN+2];int flag[LEN][LEN];int lowbit(int x) { return x & (-x);}void update(int x,原创 2012-09-15 15:12:11 · 635 阅读 · 0 评论 -
HDU 1556
区间更新,求点值#include #include int tree[1000001];int n; inline int Lowbit(int x) { return x & (-x);} inline void Update(int pos, int val) { while (pos <= n) { tree[pos] += va原创 2012-09-14 22:40:11 · 419 阅读 · 0 评论 -
HDU 1012
上完课A个题去吃饭,结果发现编译器坏了,没编译我就提交了,发现AC了#include #include #include int main() { double e; int i, tmp; e = 1; tmp = 1; printf("n e\n"); printf("- -----------\n"); printf("0 1\n"); for(i = 1; i原创 2012-11-29 18:44:36 · 2244 阅读 · 0 评论 -
UVa 674
硬币找零,其本质就是组合问题,所以在写的时候要使 coin 成严格的非递减序列具体的题号不记得了,当时用的不是记忆化搜索的方式:#include #include int step[18] = {0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289};int main() {原创 2012-12-08 18:26:13 · 486 阅读 · 0 评论 -
HDU 1098
一道关于取模运算的数学题,推倒出公式即可:一开始把num数组放在了栈空间里面,并且对于index下标没有做溢出判断,从而使得k变为了47,让我很不解,后来发现是数组溢出覆盖了。#include #include #include using namespace std;#define LEN 10000int num[LEN];int main() { int a,原创 2012-12-11 11:15:38 · 589 阅读 · 0 评论