上一页 1 2 3 4 5 6 7 8 9 10 ··· 17 下一页

2012年7月13日

188B A + Reverse B

摘要: a 加 b 的反序表示的数;# include <cstdio># include <cstring>int a, b;char s[11];void init(void){ scanf("%d%s", &a, s);}void solve(void){ b = 0; for (int i = strlen(s)-1; i >= 0; --i) { b *= 10; b += s[i]-'0'; } printf("%d\n", a+b);}int main(){ init(); solve(); r 阅读全文

posted @ 2012-07-13 22:47 getgoing 阅读(164) 评论(0) 推荐(0)

192B Walking in the Rain

摘要: 简单DP,设 f[i] 为到达第 i 个位置最迟的天数,那么 f[i] 为 min(f[i-2], a[i]) 和 min(f[i-1], a[i]) 中的较大者;# include <cstdio># include <algorithm># define N 1005using namespace std;int n, a[N];int f[N];void init(void){ scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i] 阅读全文

posted @ 2012-07-13 22:37 getgoing 阅读(203) 评论(0) 推荐(0)

205B Little Elephant and Sorting

摘要: 贪心:每次对于比前面的数小的数累加差值即可,比前面大的可以通过加大区间范围保持大小关系不变;# include <cstdio>int n, a[100005];void init(void){ int i; scanf("%d", &n); for (i = 0; i < n; ++i) scanf("%d", &a[i]);}void solve(void){ int i; long long int ans; ans = 0; for (i = 1; i < n; ++i) if (a[i] < a[i 阅读全文

posted @ 2012-07-13 22:20 getgoing 阅读(174) 评论(0) 推荐(0)

201C Fragile Bridges

摘要: dp,参考了http://www.cppblog.com/hanfei19910905/archive/2012/06/30/180831.html;定义两组状态 L1[i] 表示在 0-i 内的最大得分,L2[i] 表示从 i 出发回到 i 的最大得分,不难得到状态转移方程,最后枚举 i 组合求出最大值;# include <cstdio># include <algorithm># define N 100005using namespace std;typedef long long int LL;int n, num[N];LL L1[N], L2[N], R1 阅读全文

posted @ 2012-07-13 22:03 getgoing 阅读(392) 评论(0) 推荐(0)

190A Vasya and the Bus

摘要: 简单题,但要仔细分清所有情况,2WA;# include <cstdio>int n, m;void solve(void){ int max, min; if (!n && !m) {printf("0 0\n"); return;} if (n == 0) {puts("Impossible"); return ;} max = m==0 ? n:n+m-1; min = (n>=m ? n:m); printf("%d %d\n", min, max);}int main(){ while (~ 阅读全文

posted @ 2012-07-13 20:27 getgoing 阅读(143) 评论(0) 推荐(0)

203A Two Problems

摘要: 简单题,要注意可能做出0、1、2题,枚举所有情况即可;# include <cstdio>int a, b, x, da, db, t;int i, j;void solve(void){ if (!x || (a>=x && (a-x)%da==0 && (a-x)/da<=t-1) || (b>=x &&(b-x)%db==0&&(b-x)/db<=t-1)) { printf("YES\n"); return ; } for (i = t-1; i >= 0; - 阅读全文

posted @ 2012-07-13 20:04 getgoing 阅读(192) 评论(0) 推荐(0)

203C Photographer

摘要: 第一道A的纠结;简单题,WA了几次,最后发现AC的代码 sort 的 cmp 返回的是 bool 型,注意到这点,就 A 了,数据是不会超范围的;# include <cstdio># include <cstring># include <algorithm># define N 100005using namespace std;int n, d, a, b;int c[N], p[N];char f[N];bool cmp(const int &x, const int &y){ return c[x] < c[y];}void 阅读全文

posted @ 2012-07-13 19:40 getgoing 阅读(206) 评论(0) 推荐(0)

POJ 2528 Mayor's posters

摘要: 线段树,离散化;WA了三次,前两次主要是查询时只要遇到标记了颜色就要返回,而不是标记颜色并且没记录过就返回,后一次是空间开的小,因为离散化可能使数据量增加一倍,因此空间至少要开到区间数目的 4 倍;-----------------------------------------------------------2012/4/15View Code # include <cstdio># include <cstring># include <algorithm>using namespace std;# define N 10000 + 5int n, 阅读全文

posted @ 2012-07-13 10:55 getgoing 阅读(510) 评论(0) 推荐(0)

2012年7月12日

POJ 2503 Babelfish

摘要: 字典树,WA;----------------------------------------------------# include <stdio.h># include <string.h># define LEN 12char buf[2 * LEN], str[LEN];struct word{ char a[LEN];} ;struct tree{ tree *node[26]; char bj; word *pw; tree() { for (int i = 0; i < 26; ++i) node[i] = NU... 阅读全文

posted @ 2012-07-12 17:35 getgoing 阅读(234) 评论(0) 推荐(0)

POJ 3468 A Simple Problem with Integers

摘要: 线段树,维护区间的和,支持区间范围修改,注意由于增加的标记传递时是累加起来,结果会超出 int ,要用 long long;--------------------------------------------------------------DescriptionYou have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each number in a given int 阅读全文

posted @ 2012-07-12 15:32 getgoing 阅读(184) 评论(0) 推荐(0)

COJ 0712 Can you answer these queries II

摘要: ------------------------------------------------------------------------------------线段树的区间操作:修改区间内的值,反转区间内的值,区间查询;------------------------------------------------------------------------------------Description维护一个只有0和1的整数序列,支持以下操作:1 x y v : 将区间[x,y]之间的所有整数都变为v(v为0或1);2 x y : 将区间[x,y]之间所有的1变为0,所有的0变为 阅读全文

posted @ 2012-07-12 13:56 getgoing 阅读(273) 评论(0) 推荐(0)

HDOJ 1394 Minimum Inversion Number

摘要: 线段树,维护的是区间内整数的个数,每次插入 x 时,查询在 x 的前面比小的数的个数,并计算出比 x 大的数的个数 cnt[x] ,最后将 cnt 累加,即为逆序数;将队首的数放到队尾后逆序数改变:n-1-a[i], a[i] 为原始序列中第 i 个数的值;----------------------------------------------------------------------2012/7/15之前的代码中,cnt[i] 是记录比第 i 个数大的的在它前面出现的数的个数,第二次写发现不需要。# include <cstdio># include <cstri 阅读全文

posted @ 2012-07-12 10:38 getgoing 阅读(228) 评论(0) 推荐(0)

POJ 2352 Stars

摘要: 因为输入是按y坐标升序的,对每个点统计在它左边的个数就是它的level(线段树);DescriptionAstronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star be an amount of the stars that are not higher and not to the right of the given star. Astronomers 阅读全文

posted @ 2012-07-12 09:48 getgoing 阅读(963) 评论(0) 推荐(0)

2012年7月11日

HDOJ 4006 The kth great number

摘要: 这道题来自于 The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest 线段树求第 k 大值,包含修改和询问;----------------------------------------------------------------------------Problem DescriptionXiao Ming and Xiao Bao are playing a simple Numbers game. In a round Xiao Ming can choose to write ... 阅读全文

posted @ 2012-07-11 16:50 getgoing 阅读(363) 评论(0) 推荐(0)

POJ 3264 Balanced Lineup

摘要: 线段树的做法,1438MS;------------------------------------------------------------------DescriptionFor the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in the same order. One day Farmer John decides to organize a game of Ultimate Frisbee with some of the cows. To keep things simpl 阅读全文

posted @ 2012-07-11 15:05 getgoing 阅读(215) 评论(0) 推荐(0)

0711 Can you answer these queries I

摘要: 线段树,修改,维护区间最大最小、和;Description维护一个整数序列,支持以下操作:1 x v : 将第x个整数的值修改为v;2 x y : 查询区间[x,y]之间的最小值;3 x y : 查询区间[x,y]之间的最大值;4 x y : 查询区间[x,y]内的整数和。Input输入文件包含多组测试数据。对于每组测试数据,第一行为一个整数N(1<=N<=10^5),表示,接下来一行有N个整数,再接下来一行有一个整数M(1<=M<=10^5),表示一共有M个操作。数据保证对于查询操作结果均在int的表示范围内。Output对于每个查询均用一行输出查询的结果。Sampl 阅读全文

posted @ 2012-07-11 14:18 getgoing 阅读(284) 评论(0) 推荐(0)

Trie--字典树

摘要: 第九届中山大学校赛预选赛(2006)Problem A 信息泛滥大致题意:给出 n 个不同的字符串,再给出 m 个字符串,问这 m 个字符串中在给出的 n 个串中没有出现的个数。思路:建 Trie ,统计即可。----------------------------------------------------------# include <stdio.h>struct tree{ tree *node[26]; int bj; tree() { bj = 0; for (int i = 0; i < 26; ++i) n... 阅读全文

posted @ 2012-07-11 01:43 getgoing 阅读(167) 评论(0) 推荐(0)

POJ 3630 Trie树 TLE

摘要: 动态 Trie 会超时,DISCUSS 中有人提醒要用静态数组的 Trie,还没学;这个题要注意除了判断当前串是否有和字典中的串相同的前缀外,还要判断当前串是否是字典中串的前缀;-----------------------------------------------------------------DescriptionGiven a list of phone numbers, determine if it is consistent in the sense that no number is the prefix of another. Let's say the ph 阅读全文

posted @ 2012-07-11 01:34 getgoing 阅读(219) 评论(0) 推荐(0)

POJ 2001 Trie

摘要: 给出的单词不会重复出现,可以建立字典树,设一个域为当前结点重复次数(或者是否重复),对每个单词输出到第一个不重复的字母或者这个单词的结尾。-----------------------------------------------------------------------------------------DescriptionA prefix of a string is a substring starting at the beginning of the given string. The prefixes of "carbon" are: "c& 阅读全文

posted @ 2012-07-11 00:45 getgoing 阅读(274) 评论(0) 推荐(0)

2012年7月10日

UVa 10986 Dijkstra TLE

摘要: 时限是 3s, 当然不能用 dijksra;N 最大是 20005,数组 d[N][N] 可以开;------------------------------------------------------------------------# include <stdio.h># include <string.h># define N 20005# define M 50005# define INF N*Mint n, m, s, t;int w[N][N];int min(int x, int y){ return (x<y ? x:y);}void in 阅读全文

posted @ 2012-07-10 10:40 getgoing 阅读(226) 评论(0) 推荐(0)

上一页 1 2 3 4 5 6 7 8 9 10 ··· 17 下一页

导航