A.Helpful Maths

分析:将读入的字符转化为数字,直接排个序就可以了。

#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std; const int N = ;
int seq[N]; int main() {
char c;
int t = , idx = ;
while ((c = getchar()) != EOF) {
if (c == '+' || c == '\n') {
seq[idx++] = t;
t = ;
}
else t = t * + c - '';
}
sort(seq, seq+idx);
printf("%d", seq[]);
for (int i = ; i < idx; ++i) printf("+%d", seq[i]);
puts("");
return ;
}

B.Xenia and Ringroad

分析:模拟即可,大于当前位置直接走,否则绕一圈后走到目标位置。

#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std; typedef long long LL;
int n, m; int main() {
while (scanf("%d %d", &n, &m) != EOF) {
int last = , x;
LL ret = ;
while (m--) {
scanf("%d", &x);
if (x >= last) {
ret += x - last;
last = x;
} else {
ret += n-last+x;
last = x;
}
}
printf("%I64d\n", ret);
}
return ;
}

C.Xenia and Weights

分析:直接搜索即可,无法证明为何会如此快的找到答案或者退出。

#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int N = ;
char str[];
int m;
int path[N]; bool dfs(int p, int left, int right, int last) {
if (p == ) return true;
int delta = abs(left-right);
for (int i = ; i <= ; ++i) {
if (last == i) continue;
if (str[i] && delta >= && delta < i) {
path[p] = i;
if (left < right) {
if (dfs(p-, left+i, right, i)) return true;
}
else if (dfs(p-, left, right+i, i)) return true;
}
}
return false;
} int main() {
scanf("%s", str+);
scanf("%d", &m);
for (int i = ; i <= ; ++i) str[i] -= '';
if (!dfs(m, , , )) {
puts("NO");
} else {
puts("YES");
for (int i = m; i > ; --i) {
printf(i == m ? "%d" : " %d", path[i]);
}
puts("");
}
return ;
}

D.Xenia and Bit Operations

分析:由于每次改变的位置只会改变与其相关位置的变化,对于其余部分的结果可以使用map存储起来,写的时候对log2(x)没有处理好,导致精度误差,教训啊。

#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std; const int N = (<<)+;
int n, m;
int seq[N];
int cpy[N];
map<pair<int,int>, int>mp;
map<pair<int,int>, int>::iterator it; int cal(int p, int l, int r) {
if (r - l == ) return mp[make_pair(l, r)] = (seq[l] | seq[r]);
int mid = (r+l) >> ;
int f = (int)floor(log((r-l+)*1.0)/log(2.0)+0.5); // 直接除取整会带来精度丢失
if (p <= mid) {
if (f & ) {// or
return (mp[make_pair(l, mid)] = cal(p, l, mid)) | mp[make_pair(mid+, r)];
} else {
return (mp[make_pair(l, mid)] = cal(p, l, mid)) ^ mp[make_pair(mid+, r)];
}
} else {
if (f & ) {
return mp[make_pair(l, mid)] | (mp[make_pair(mid+, r)] = cal(p, mid+, r));
} else {
return mp[make_pair(l, mid)] ^ (mp[make_pair(mid+, r)] = cal(p, mid+, r));
}
}
} int main() {
scanf("%d %d", &n, &m);
int LIM = << n;
for (int i = ; i <= LIM; ++i) {
scanf("%d", &seq[i]);
cpy[i] = seq[i];
}
for (int i = , k = ; i < LIM; i <<= , ++k) {
for (int j = ; j+i <= LIM; j += (i<<)) {
if (k & ) { // xor
cpy[j] ^= cpy[j+i];
mp[make_pair(j, j+(i<<)-)] = cpy[j];
} else { // or
cpy[j] |= cpy[j+i];
mp[make_pair(j, j+(i<<)-)] = cpy[j];
}
}
}
int p, b;
while (m--) {
scanf("%d %d", &p, &b);
seq[p] = b;
printf("%d\n", cal(p, , LIM));
}
return ;
}

Codeforces Round #197 (Div. 2)的更多相关文章

  1. 线段树 Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations

    题目传送门 /* 线段树的单点更新:有一个交叉更新,若rank=1,or:rank=0,xor 详细解释:http://www.xuebuyuan.com/1154895.html */ #inclu ...

  2. Codeforces Round #197 (Div. 2) : E

    看了codeforces上的大神写的题解之后,才知道这道题水的根本! 不过相对前面两题来说,这道题的思维要难一点: 不过想到了水的根本,这题也真心不难: 方法嘛,就像剥洋葱一样,从外面往里面剥: 所以 ...

  3. [置顶] Codeforces Round #197 (Div. 2)(完全)

    http://codeforces.com/contest/339/ 这场正是水题大放送,在家晚上限制,赛后做了虚拟比赛 A,B 乱搞水题 C 我是贪心过的,枚举一下第一个拿的,然后选使差值最小的那个 ...

  4. Codeforces Round #197 (Div. 2) (A、B、C、D、E五题合集)

    A. Helpful Maths 题目大意 给一个连加计算式,只包含数字 1.2.3,要求重新排序,使得连加的数字从小到大 做法分析 把所有的数字记录下来,从小到大排序输出即可 参考代码 #inclu ...

  5. Codeforces Round #197 (Div. 2) C,D两题

    开了个小号做,C题一开始看错范围,D题看了半小时才看懂,居然也升到了div1,囧. C - Xenia and Weights 给出一串字符串,第i位如果是1的话,表示有重量为i的砝码,如果有该种砝码 ...

  6. Codeforces Round #197 (Div. 2) : C

    哎....这次的比赛被安叔骂的好惨! 不行呢,要虐回来: 这道搜索,老是写错,蛋疼啊! 果然是基础没打好! #include<cstdio> using namespace std; ], ...

  7. Codeforces Round #197 (Div. 2) : D

    这题也是一个线段树的水题: 不过开始题目没看明白,害得我敲了一个好复杂的程序.蛋疼啊.... 最后十几分钟的时候突然领悟到了题意,但是还是漏掉一个细节,老是过不去... 以后比赛的时候不喝啤酒了,再也 ...

  8. Codeforces Round #197 (Div. 2) : B

    也是水题一个,不过稍微要细心点.... 贴代码: #include<iostream> using namespace std; long long n,m; ; int main() { ...

  9. Codeforces Round #197 (Div. 2) : A

    水题一个: 直接贴代码: #include<cstdio> #include<algorithm> #include<cstring> using namespac ...

随机推荐

  1. 鸟哥的linux私房菜---非常好的linux基础网址【转】

    转自:http://linux.vbird.org/linux_basic/0320bash.php 在 Linux 的環境下,如果你不懂 bash 是什麼,那麼其他的東西就不用學了!因為前面幾章我們 ...

  2. MySQL Replication的Reset slave重置命令

    有时要清除从库的所有复制信息,如切换为不同的Master, 主从重做等:Reset slave是一个比较危险的命令,所以在执行前一定要准备知道其含义. 1. 命令在slave上执行,执行前一定要停掉s ...

  3. ASP+Access UTF-8 网页乱码问题解决办法

    用ACCESS数据库和ASP做网站时用UTF-8编码有时会出现乱码,再者网页出错或者刷新页面后就是乱码,如果数据库取值乱码在开头加上<%@LANGUAGE="VBSCRIPT" ...

  4. ecshop销售排行调用促销价格和市场价格

    我们知道在ecshop某些产品销售之后,销售量高的产品销售出去之后,能形成销售排行,ecshop的销售排行必须保持两个条件,首先是ecshop的商品必须库存足够,其次商品该商品必须上架的. 我们分析如 ...

  5. Java异常捕获之try-catch-finally-return的执行顺序-转载

    情况1:try块中没有抛出异常try和finally块中都有return语句 public static int NoException(){ int i=10; try{ System.out.pr ...

  6. java.lang.IllegalThreadStateException

    java.lang.IllegalThreadStateException 今天遇到了这个问题.当时的情景是想要循环实现了runable的类和继承Thread类的两个线程.可是没有注意到,继承自Thr ...

  7. SlickGrid example 5:带子项的展开收缩

    带子项的展开收缩.   代码: <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Ty ...

  8. Epoll,Poll,Select模型比较

    http://blog.csdn.net/liangyuannao/article/details/7776057 先说Select: 1.Socket数量限制:该模式可操作的Socket数由FD_S ...

  9. Codeforces Round #368 (Div. 2) C

    Description Katya studies in a fifth grade. Recently her class studied right triangles and the Pytha ...

  10. [Codeforces626F] Group Projects (DP)

    Group Projects Description There are n students in a class working on group projects. The students w ...