Codeforces Round #327 (Div. 2)
2016-07-19 04:16
253 查看
A - Wizards' Duel
题意不想解释了,说了一大堆没用的东西。
分析:直接公式p*l/(p+q)就ok了。数据全用double。
题意:更改字符串的字符,每次操作把所有的字符a和字符b交换。
分析:数据到了2e5,暴力的话会爆时间,可以建立一个映射表示各个字符应转换到的字符。每次操作更新数组即可。
题意:一串01序列,每次变换第一个数个最后一个数不变,从第二个数到倒数第二个数分别等于自己与相邻两个数的中位数。变换有限次直到不发生变化时的状态称为稳定态,存在稳定态就输出变换到稳定态需要的变换次数和他的稳定态,否则,输出-1。
分析:观察可得相邻两个数相同时这两个数是不发生变化的,其余的全是01相间的情况。
对01相间的情况考虑,它有两个端点,两个端点相同时,里面所有的数都为端点数;两个端点不同时,一半的数跟随端点变化。
变化的次数也由01相间的序列决定,在所有的可能值中取最大值。
题意不想解释了,说了一大堆没用的东西。
分析:直接公式p*l/(p+q)就ok了。数据全用double。
#include <cstdio> #include <cstring> #include <algorithm> #include <iostream> #include <string> #include <vector> #include <stack> #include <bitset> #include <cstdlib> #include <cmath> #include <set> #include <list> #include <deque> #include <map> #include <queue> using namespace std; typedef long long ll; typedef unsigned long long ull; const double PI = acos(-1.0); const double eps = 1e-6; const int INF = 1000000000; const int maxn = 100; double l, n, m; int main() { cin >> l >> n >> m; double ans; ans = l/(n+m); ans = ans*n; cout << ans << endl; return 0; }B - Rebranding
题意:更改字符串的字符,每次操作把所有的字符a和字符b交换。
分析:数据到了2e5,暴力的话会爆时间,可以建立一个映射表示各个字符应转换到的字符。每次操作更新数组即可。
#include <iostream> #include <string> #include <cstring> using namespace std; char map[1000]; int main() { int n, m; string s; for(int i = 'a' ; i <= 'z' ; i ++) { map[i] = i; } cin >> n >> m ; cin >> s; for(int i = 0 ; i < m ; i ++) { char a, b; cin >> a >> b; for(char i = 'a' ; i <= 'z' ; i ++) { if(map[i] == a) {map[i] = b;} else if(map[i] == b) {map[i] = a;} } } for(int i = 0 ; i < n ; i ++) s[i] = map[s[i]]; cout << s << endl; return 0; }C - Median Smoothing
题意:一串01序列,每次变换第一个数个最后一个数不变,从第二个数到倒数第二个数分别等于自己与相邻两个数的中位数。变换有限次直到不发生变化时的状态称为稳定态,存在稳定态就输出变换到稳定态需要的变换次数和他的稳定态,否则,输出-1。
分析:观察可得相邻两个数相同时这两个数是不发生变化的,其余的全是01相间的情况。
对01相间的情况考虑,它有两个端点,两个端点相同时,里面所有的数都为端点数;两个端点不同时,一半的数跟随端点变化。
变化的次数也由01相间的序列决定,在所有的可能值中取最大值。
#include <iostream> using namespace std; const int maxn = 500000 + 5; int a[maxn]; int n; int main() { int ans = 0; cin >> n ; for(int i = 0 ; i < n ; i ++) cin >> a[i]; for(int i = 0 ; i < n - 1 ; i ++ ) { if(i) i--; int j = i; while(i<n-1&&a[i]!=a[i+1]) i++; for(int k = j ; k <= i ; k ++) { if(k<=(i+j)/2) a[k] = a[j]; else a[k] = a[i]; } ans = ans>(i-j)/2?ans:(i-j)/2; while(i<n-1&&a[i]==a[i+1]) i++; } cout << ans << endl; for(int i = 0 ; i < n ; i ++) cout << a[i] << ' '; cout << endl; return 0; }
相关文章推荐
- Codeforces Round #197 (Div. 2)
- Codeforces Round #198 (Div. 1)
- Codeforces 405E Codeforces Round #238 (Div. 2)E
- Codeforces 407C Codeforces Round #239 (Div. 1)C
- CodeForces 449A - Jzzhu and Chocolate
- CodeForces 449 B. Jzzhu and Cities
- codeforces 618C. Constellation
- Codeforces Round #349 (Div. 2) - C
- Codeforces Round #361 (Div. 2)
- 7.13Codeforces Round #360 (Div. 2)
- Codeforces Round #265 (Div. 2)
- Codeforces #310 div2 C. Case of Matryoshkas
- 状态压缩DP codeforces 244 Problem C. The Brand New Function 和 codeforces 165 E. Compatible Numbers
- codeforces 16 Problem E fish
- Codeforces Round332 部分题解
- CodeForces 603A_Alternative Thinking (DP)
- CodeForces 602B_Approximating a Constant Range_DP
- Codeforces round #247 for Div. 2
- Codeforces Round #246 (Div. 2)
- Codeforces Round #356 (Div. 2)