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 ...
随机推荐
- WPF:窗体置顶
1.设置窗体TopMost属性 private DispatcherTimer timer; public Window1() { InitializeComponent(); Loaded += n ...
- Postgres-XL集群搭建
Postgres-XL 是一个完全满足ACID的.开源的.可方便进行水平扩展的.多租户安全的.支持share-nothing;支持海量数据并行处理-MPP(Massively Parallel Pro ...
- AjaxPro 的基本用法
通过 Ajax可以直接访问后台的代码 实现的步骤: 一 ,添加 引用 AjaxPro.2.dll 文件 二 配置配置文件 <httpHandlers> <add verb=" ...
- sql 语法
CASE ISNULL(b.enddate , '2000-1-1') WHEN '2000-1-1' THEN '未发稿' ELSE '已经发稿' END 如果时间为空,则显示为值‘200-1-1’ ...
- 20145227《Java程序设计》第10周学习总结
20145227<Java程序设计>第10周学习总结 教材学习内容总结 网络编程 就是在两个或两个以上的设备(例如计算机)之间传输数据.程序员所作的事情就是把数据发送到指定的位置,或者接收 ...
- Serializable接口使用纪实
这两天依领导要求使用sonar工具测试了一下项目代码,其中有一个问题是 而这个类的结构大概是这样的: public class Demo<T> implements Serializabl ...
- quick lua 使用spine骨骼动画
看下下面两个文件 <spine/SkeletonRenderer.h><spine/SkeletonAnimation.h> 1.lua中创建方法: sp.SkeletonAn ...
- 关于IllegalMonitorStateException异常
关于IllegalMonitorStateException异常: api中的解释 另请参见: Object.notify(), Object.notifyAll(), Object.wait(), ...
- SDUT 2877:angry_birds_again_and_again
angry_birds_again_and_again Time Limit: 2000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 The problems ...
- The Cow Lexicon
The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8815 Accepted: 4162 Descr ...