Codeforces Round #327 (Div. 2)

A - Wizards' Duel

题意不想解释了,说了一大堆没用的东西。

分析:直接公式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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值