Codeforces Round #197 (Div. 2)
分析:将读入的字符转化为数字,直接排个序就可以了。
#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 ;
}
分析:模拟即可,大于当前位置直接走,否则绕一圈后走到目标位置。
#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 ;
}
分析:直接搜索即可,无法证明为何会如此快的找到答案或者退出。
#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 ;
}
分析:由于每次改变的位置只会改变与其相关位置的变化,对于其余部分的结果可以使用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)的更多相关文章
- 线段树 Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations
题目传送门 /* 线段树的单点更新:有一个交叉更新,若rank=1,or:rank=0,xor 详细解释:http://www.xuebuyuan.com/1154895.html */ #inclu ...
- Codeforces Round #197 (Div. 2) : E
看了codeforces上的大神写的题解之后,才知道这道题水的根本! 不过相对前面两题来说,这道题的思维要难一点: 不过想到了水的根本,这题也真心不难: 方法嘛,就像剥洋葱一样,从外面往里面剥: 所以 ...
- [置顶] Codeforces Round #197 (Div. 2)(完全)
http://codeforces.com/contest/339/ 这场正是水题大放送,在家晚上限制,赛后做了虚拟比赛 A,B 乱搞水题 C 我是贪心过的,枚举一下第一个拿的,然后选使差值最小的那个 ...
- Codeforces Round #197 (Div. 2) (A、B、C、D、E五题合集)
A. Helpful Maths 题目大意 给一个连加计算式,只包含数字 1.2.3,要求重新排序,使得连加的数字从小到大 做法分析 把所有的数字记录下来,从小到大排序输出即可 参考代码 #inclu ...
- Codeforces Round #197 (Div. 2) C,D两题
开了个小号做,C题一开始看错范围,D题看了半小时才看懂,居然也升到了div1,囧. C - Xenia and Weights 给出一串字符串,第i位如果是1的话,表示有重量为i的砝码,如果有该种砝码 ...
- Codeforces Round #197 (Div. 2) : C
哎....这次的比赛被安叔骂的好惨! 不行呢,要虐回来: 这道搜索,老是写错,蛋疼啊! 果然是基础没打好! #include<cstdio> using namespace std; ], ...
- Codeforces Round #197 (Div. 2) : D
这题也是一个线段树的水题: 不过开始题目没看明白,害得我敲了一个好复杂的程序.蛋疼啊.... 最后十几分钟的时候突然领悟到了题意,但是还是漏掉一个细节,老是过不去... 以后比赛的时候不喝啤酒了,再也 ...
- Codeforces Round #197 (Div. 2) : B
也是水题一个,不过稍微要细心点.... 贴代码: #include<iostream> using namespace std; long long n,m; ; int main() { ...
- Codeforces Round #197 (Div. 2) : A
水题一个: 直接贴代码: #include<cstdio> #include<algorithm> #include<cstring> using namespac ...
随机推荐
- Java类加载信息的顺序:包括静态代码快、静态类变量、非静态代码快、构造方法、普通方法
JVM运行之前会执行一个叫做类加载器的子系统,叫做ClassLoader,那么类里面那么多“元素”,究竟是个什么顺序呢,写几行代码测试一下,通过给每个方法和代码快和静态变量打上断点来测试: class ...
- n阶乘 尾数0的个数
class Solution {public: int trailingZeroes(int n) { if(n<=0) return 0; int i=0; ...
- HDU 2846:Repository(Trie)
http://acm.hdu.edu.cn/showproblem.php?pid=2846 题意:给出N个模式串,再给出M个文本串,问每一个文本串在多少个模式串中出现. 思路:平时都是找前缀的,这里 ...
- easyui常现错误
1.easyui-tabs:当data-options的属性设置为true时,其tab内部的内容显示不出来. 2.设置easyui-panel的title格式及字体大小无效 解决方法:在设置title ...
- linux命令:du 命令
Linux du命令也是查看使用空间的,但是与df命令不同的是Linux du命令是对文件和目录磁盘使用的空间的查看,还是和df命令有一些区别的. 1.命令格式: du [选项][文件] 2.命令功能 ...
- 使用System.arraycopy()实现数组之间的复制
System提供了一个静态方法arraycopy(),我们可以使用它来实现数组之间的复制. 其函数原型是: public static void arraycopy(Object src, int s ...
- (翻译)理解Java当中的回调机制
原文地址:http://cleancodedevelopment-qualityseal.blogspot.com/2012/10/understanding-callbacks-with-java. ...
- Paratroopers
Paratroopers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7881 Accepted: 2373 Descript ...
- CSUFT 1003 All Your Base
1003: All Your Base Time Limit: 1 Sec Memory Limit: 128 MB Submit: 4 Solved: 2 Description ...
- Hadoop Mac OSX 安装笔记
本次测试安装的机器为Mac Book Pro, 系统为 OS X 10.9.4.Hadoop版本2.4.1. 使用Java版本为Oracle的JDK 1.6.0_65. 1. 下载安装 Hadoop2 ...