Codeforces Round #327 (Div. 2)
题目都没看清就写了,1e-4精度WA了一次。。。
/************************************************
* Author :Running_Time
* Created Time :2015/10/25 16:27:20
* File Name :A.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7; int main(void) {
int L, p, q;
scanf ("%d%d%d", &L, &p, &q);
double ans = L * (p * 1.0) / (p + q);
printf ("%.5f\n", ans); return 0;
}
题意:要求字符串的所有C1字符变成C2,C2变成C1,输出最后的结果
分析:想了一会,试了并查集,未果,YY,未果。最后想了一个很奇怪的方法,就是每次记录C1的最原始的字符rt[C1],它将转换为C2,即to[rt[C1]] = C2
/************************************************
* Author :Running_Time
* Created Time :2015/10/25 16:27:20
* File Name :B.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 2e6 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
char s[N];
int to[30], rt[30]; int main(void) {
int n, m; scanf ("%d%d", &n, &m); getchar ();
scanf ("%s", &s); getchar ();
char c1, c2;
memset (to, -1, sizeof (to));
for (int i=0; i<26; ++i) rt[i] = i;
for (int i=1; i<=m; ++i) {
scanf ("%c %c", &c1, &c2); getchar ();
int tmp = rt[c2-'a'];
to[rt[c1-'a']] = c2 - 'a';
to[rt[c2-'a']] = c1 - 'a';
rt[c2-'a'] = rt[c1-'a'];
rt[c1-'a'] = tmp;
}
for (int i=0; i<n; ++i) {
if (to[s[i]-'a'] == -1) printf ("%c", s[i]);
else printf ("%c", 'a' + to[s[i]-'a']);
}
puts (""); return 0;
}
题意:由01构成的序列,每一次a[i] = (a[i-1], a[i], a[i+1])的第二大,问多少次序列会稳定
分析:列出(a[i-1], a[i], a[i+1])的所有组合,发现只有010和101是不稳定的,所以找出这样的连续的最长的串,操作次数就是max_len / 2
/************************************************
* Author :Running_Time
* Created Time :2015/10/25 16:27:20
* File Name :C.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 5e5 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
int a[N]; int main(void) {
int n; scanf ("%d", &n);
for (int i=1; i<=n; ++i) {
scanf ("%d", &a[i]);
}
int ans = 0;
for (int i=2; i<n; ++i) {
if (a[i] != a[i-1]) {
int j = i;
while (j < n && a[j] != a[j+1] && a[j] != a[j-1]) j++;
ans = max (ans, (j - i + 1) >> 1);
int p = i, q = j - 1;
while (p <= q) {
a[p++] = a[i-1];
a[q--] = a[j];
}
i = j;
}
}
printf ("%d\n", ans);
for (int i=1; i<=n; ++i) {
printf ("%d%c", a[i], i == n ? '\n' : ' ');
} //cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; return 0;
}
Codeforces Round #327 (Div. 2)的更多相关文章
- Codeforces Round #327 (Div. 2) A. Wizards' Duel 水题
A. Wizards' Duel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/prob ...
- Codeforces Round #327 (Div. 2) E. Three States BFS
E. Three States Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/probl ...
- Codeforces Round #327 (Div. 2) D. Chip 'n Dale Rescue Rangers 二分 物理
D. Chip 'n Dale Rescue Rangers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/co ...
- Codeforces Round #327 (Div. 2) C. Median Smoothing 找规律
C. Median Smoothing Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/p ...
- Codeforces Round #327 (Div. 2) B. Rebranding 水题
B. Rebranding Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/problem ...
- Codeforces Round #327 (Div. 1), problem: (A) Median Smoothing
http://codeforces.com/problemset/problem/590/A: 在CF时没做出来,当时直接模拟,然后就超时喽. 题意是给你一个0 1串然后首位和末位固定不变,从第二项开 ...
- Codeforces Round #327 (Div. 2) B. Rebranding C. Median Smoothing
B. Rebranding The name of one small but proud corporation consists of n lowercase English letters. T ...
- Codeforces Round #327 (Div. 2)B(逻辑)
B. Rebranding time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Codeforces Round #327 (Div. 2)-Wizards' Duel
题意: 在一条长度为l的走廊,两个人站在走廊的左右两端分别以p,q的速度走来,问他们相遇时离左端的距离是多少? 思路: 非常简单的暴力题,不解释. 代码如下: #include <iostrea ...
随机推荐
- cocos基础教程(2)Window环境下搭建
第一步:开始安装VS2012 第二步:下载Cocos2d-x 3.4源码 配置环境变量 COCOS_CONTROL = E:\cocos2d-x-3.4\tools\cocos2d-console ...
- Codeforces Round #FF (Div. 2) C. DZY Loves Sequences
解题报告:输入一个数列,选取一个子数列,要求最多只能改动这个子数列中的一个数,使得这个子数列是严格的升序的(严格升序没有相等的) 我的做法是,第一步把这个 数列的每个升序的子数列都找出来,然后看这些子 ...
- linux下软件安装的方法
linux下软件的安装与卸载 第一章 linux下安装软件,如何知道软件安装位置 注:一般的软件的默认安装目录在 jdk-1_6_0_14-linux-i586-rpm.bin ←修改为 ...
- HTML快速入门3
四.表格 (Table) 1. 表格的基本形式 表由 <table> 开始, </table> 结束,表的内容由 <tr>,<th> 和 <td& ...
- [ruby on rails] 跟我学之(2)HelloWorld
1. 创建工程 rails new blog 2.查看下文件结构 tree 输出如下,请留意红圈中的部分. Gemfile, 用来管理应用程序的gems, 有点类似于python的包,有专门的网站来查 ...
- Ubuntu上如何安装Java,Eclipse,Pydev,Python(自带,不用装),BeautifulSoup
如何安装Java,如果出于编程的需要安装Java,需要安装的是JDK,而不仅仅是JRE,下面说说如何在Ubuntu下如何安装JDK:只有两步,1.下载并解压,2.配置环境变量1.下载并解压:下载地址: ...
- 使用MegaCli和Smartctl获取普通磁盘
设备名称: [root@DB232 shell]# cat /proc/scsi/scsi Attached devices:Host: scsi0 Channel: 02 Id: 00 Lun: 0 ...
- 【GoLang】GO语言系列--001.GO开发环境搭建
- spring中context:property-placeholder/元素
1.有些参数在某些阶段中是常量 比如 :a.在开发阶段我们连接数据库时的连接url,username,password,driverClass等 b.分布式应用中client端访问server端所用的 ...
- Android Studio在线安装Android SDK注意事项
由于使用的Android studio自带了sdk23,然而其它版本的sdk并没有安装:这些天由于需要用到低版本的sdk,因而使用Android SDK Manager进行相应的更新.开始的时候老是无 ...