Hdu 3363 Ice-sugar Gourd(思路)

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=3363

思路:有解:两种情况。第一种,中间一分刚好,即切一刀。第二种,将第一个与最后一个连接起来,组成一个圆,过圆心将圆分成两部分,总有一种方式符合题意。枚举起点i,判断sum[i+n/2]-sum[i]是否等于H/2即可。

#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=1e5+50;
int n,H,T;
//int sumt[maxn];
int sumh[maxn];
char st[maxn];
int main()
{
    //freopen("in.in","r",stdin);
    //freopen("out.out","w",stdout);
    while(scanf("%d",&n)==1&&n)
    {
        H=0,T=0;
        memset(sumh,0,sizeof(sumh));
        //memset(sumt,0,sizeof(sumt));
        scanf("%s",st+1);
        for(int i=1; i<=n; i++)
        {
            if(st[i]=='H') H++;
            else T++;
            sumh[i]=H;
        }
        if((H%2)||(T%2)||(n&1))
        {
            printf("-1\n");
            continue;
        }
        if(sumh[n/2]==H/2)
            printf("1\n%d\n",n/2);
        else
            for(int i=1; i<=n/2; i++)
            {
                if(sumh[i+n/2]-sumh[i]==H/2)
                {
                    printf("2\n%d %d\n",i,i+n/2);
                    break;
                }
            }
    }
    return 0;
}
时间: 2024-08-10 17:45:08

Hdu 3363 Ice-sugar Gourd(思路)的相关文章

Hdu 3667 Transportation(最小费用流+思路)

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=3667 思路:平方关系,直接建图每次增广并不是最优.... 1^2=1,2^2=1+3,3^2=1+3+5,4^2=1+3+5+7....... 所以,对于每条边<x,y>,若流量为c,则在x与y之间连c条边,流量均为1,费用分别为a[i],3*a[i],5*a[i].........由于每次增广时流量相同时选择最小花费的边,若该边<x,y>流量为c,则总花费为a[x]+3*a[x]+5

HDU 1172.猜数字【思路转换,思维练习】【枚举】【8月8】

猜数字 Problem Description 猜数字游戏是gameboy最喜欢的游戏之一.游戏的规则是这样的:计算机随机产生一个四位数,然后玩家猜这个四位数是什么.每猜一个数,计算机都会告诉玩家猜对几个数字,其中有几个数字在正确的位置上. 比如计算机随机产生的数字为1122.如果玩家猜1234,因为1,2这两个数字同时存在于这两个数中,而且1在这两个数中的位置是相同的,所以计算机会告诉玩家猜对了2个数字,其中一个在正确的位置.如果玩家猜1111,那么计算机会告诉他猜对2个数字,有2个在正确的位

最短路(数据处理):HDU 5817 Ice Walls

Have you ever played DOTA? If so, you may know the hero, Invoker. As one of the few intelligence carries, Invoker has 10 powerful abilities. One of them is the Ice Wall: Invoker generates a wall of solid ice directly in front of him, and the bitter c

hdu 5480(维护前缀和+思路题)

Conturbatio Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 786    Accepted Submission(s): 358 Problem Description There are many rook on a chessboard, a rook can attack the row and column it be

HDU 5325 Crazy Bobo(思路+dfs 记忆化)

Crazy Bobo Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 612    Accepted Submission(s): 189 Problem Description Bobo has a tree,whose vertices are conveniently labeled by 1,2,...,n.Each node

HDU 6318 Swaps and Inversions 思路很巧妙!!!(转换为树状数组或者归并求解逆序数)

Swaps and Inversions Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2315    Accepted Submission(s): 882 Problem Description Long long ago, there was an integer sequence a.Tonyfang think this se

2014 Super Training #1 C Ice-sugar Gourd 模拟,扫描线

原题 HDU 3363 http://acm.hdu.edu.cn/showproblem.php?pid=3363 给你一个串,串中有H跟T两种字符,然后切任意刀,使得能把H跟T各自分为原来的一半. 解法: 把串想象成一个环,只要满足H跟T都为偶数个,那么就可以做一条过圆心的直线把H跟T平分掉,过直线,只要考虑平分H或者T中的一个就可以了,因为直线本来就把环平分,而此时平分了H或者T,那么剩下的那个也是平分掉的. 具体证明: http://hi.baidu.com/superlong/item

HDU 5001 Walk(鞍山网络赛E题)

HDU 5001 Walk 题目链接 思路:枚举每个要经过的点,然后进行状态转移,状态为dp[i][j],状态表示当前在j的点,已经走了i步,每次转移的时候,不从这个枚举的点出发,这样就可以求出所有路径经过该点的概率p, 然后1 - p就是不经过的答案 代码: #include <cstdio> #include <cstring> #include <vector> #include <algorithm> using namespace std; con

HDU 4981 Goffi and Median(水)

HDU 4981 Goffi and Median 思路:排序就可以得到中间数,然后总和和中间数*n比较一下即可 代码: #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; const int N = 1005; int n, a[N], sum; int main() { while (~scanf("%d&