2012年7月13日

187A Permutations

摘要: 这道题和“扑克牌排序”很相似,但是并不是排成升序,可以用同一种方式对两个序列排序,使第二个为升序,此时第一个序列就成了“扑克牌排序”的情况,只需要统计出第一次逆序出现的位置即可,由于是排列,可以用 O(n) 的方法来做;# include <cstdio># define N 200010int n, a[N], b[N];int p[N];void init(void){ scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); for (int 阅读全文

posted @ 2012-07-13 23:51 getgoing 阅读(206) 评论(0) 推荐(0) 编辑

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 阅读(144) 评论(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 阅读(189) 评论(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 阅读(162) 评论(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 阅读(376) 评论(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 阅读(131) 评论(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 阅读(179) 评论(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 阅读(197) 评论(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 阅读(493) 评论(0) 推荐(0) 编辑

导航