CodeForces 604C 【思维水题】`

题意:

给你01字符串的长度再给你一个串。

然后你可以在这个串中选择一个起点和一个终点使得这个连续区间内所有的位取反。

求:

经过处理后最多会得到多少次01变换。

例如:0101是4次,0001是2次,000110是3次。

分析:

区间内部的数目是不会发生变化的,因为每一位都是按位取反,相当于都没变,唯一发生变化的是区间边缘,所以考虑到连续的两个或多个1或者0的时候在其中某处设置断点会使得变换次数增加,很容易理解当某处有两个连续点的时候变换次数增加1,因为一个区间只有两个端点所以变换次数最多增加两次。

——————————————————————————————————————————

以上是屌丝一开始的思维,所以开始写码....

代码过了...但是发现一个问题...

当连续的3个或者3个以上点的时候把区间设置在这些连续点的内部可以增加的变换次数直接+2...

再看屌丝自己的代码...奥发现代码跟原来的想法根本不一样,只是恰好在连续的三个或者三个以上的时候设置了正确的标志变量...

#include<stdio.h>
int tmp[100500];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%1d",&tmp[i]);
    }
    int ans=1,ttt=1;
    bool ok=0,ook=0;
    for(int i=2;i<=n;i++)
    {
        if(tmp[i]==tmp[i-1])
        {
            ttt++;
            if(ttt>=2)//代码的bug成了简化代码的手段...
            {
                if(!ok)
                    ok=1;
                else
                  ook=1;
            }
        }
        else
        {
            ttt=1;
            ans++;
        }
    }
    printf("%d\n",ans+ok+ook);
}
时间: 2024-08-11 01:35:49

CodeForces 604C 【思维水题】`的相关文章

CodeForces 20B Equation 水题

题目链接:点击打开链接 #include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <iostream> #include <map> #include <set> #include <math.h> using namespace std; #define inf 10000000 #define l

CodeForces 705A Hulk (水题)

题意:输入一个 n,让你输出一行字符串. 析:很水题,只要判定奇偶性,输出就好. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #include <cstring

HDOJ/HDU 1256 画8(绞下思维~水题)

Problem Description 谁画8画的好,画的快,今后就发的快,学业发达,事业发达,祝大家发,发,发. Input 输入的第一行为一个整数N,表示后面有N组数据. 每组数据中有一个字符和一个整数,字符表示画笔,整数(>=5)表示高度. Output 画横线总是一个字符粗,竖线随着总高度每增长6而增加1个字符宽.当总高度从5增加到6时,其竖线宽度从1增长到2.下圈高度不小于上圈高度,但应尽量接近上圈高度,且下圈的内径呈正方形. 每画一个"8"应空一行,但最前和最后都无空

Iroha and a Grid AtCoder - 1974(思维水题)

就是一个组合数水题 偷个图 去掉阴影部分  把整个图看成上下两个矩形 对于上面的矩形求出起点到每个绿点的方案 对于下面的矩形 求出每个绿点到终点的方案 上下两个绿点的方案相乘后相加 就是了 想想为什么 #include <iostream> #include <cstdio> #include <sstream> #include <cstring> #include <map> #include <cctype> #include

codeforces 804A Find Amir 思维/水题

A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends. There are n schools numerated from 1 to n. One can travel between each pair of them, to d

CodeForces 474B Worms (水题,二分)

题意:给定 n 堆数,然后有 m 个话询问,问你在哪一堆里. 析:这个题是一个二分题,但是有一个函数,可以代替写二分,lower_bound. 代码如下: #include<bits/stdc++.h> using namespace std; typedef long long LL; const int maxn = 1e5 + 5; int a[maxn]; int main(){ int n, m; cin >> n; for(int i = 1; i <= n; +

codeforces 377A. Puzzles 水题

A. Puzzles Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/337/A Description The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to p

【Gym - 100923A】Por Costel and Azerah(思维水题)

Por Costel and Azerah Descriptions 给你n个数 问你,有多少个子序列 的和是偶数 Example Input 233 10 124 2 Output 33 题目链接 https://vjudge.net/problem/Gym-100923A 恶心死了   freopen("azerah.in","r",stdin); freopen("azerah.out","w",stdout); 必须加

CodeForces 709A Juicer (水题, 模拟)

题意:给定 n 个桔子的大小,一个杯子的容积,一个最大限度,挨着挤桔子汁,如果大小大于限度,扔掉,如果不杯子满了倒掉,问你要倒掉多少杯. 析:直接按要求模拟就好,满了就清空杯子. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath&g