timus 1427. SMS URAL 解题报告 题意好坑啊

timus   1427. SMS  URAL  解题报告

坑死人的题意啊!  网上又找不到翻译,好得找到一个解题报告还没有解释,后来看了discuss才有了灵感!
没办法,按照我的理解写一下吧(有错误请喷就好了):

就是SMS信息转发机制是需要付费的,一条很长的信息是不能一次发送完毕的,得分成好几条来发,但是SMS是按照条数收费的;为了省钱,一条信息尽可能少分几条!
当然,你不可能把信息打乱吧?!!  就像人们发短息一样,如果太长的话会被移动截断分成几条来发,为了给你省钱,每条短信只有达到字数限制才能截断!

但问题是这个字数是分两种计数方式的,因为普通字符(拉丁文和空格)和标点符号等的编码不一样,后者可能占得容量大,那到底如果计数呢?  就来个简单的计数方式吧!
如果是普通字符,可以达到m个(m>n);  其他任意字符(就是中间夹杂着特殊字符的)只能最多n个;
这样明白了吗?如果还不明白,请看几个样例:
3    5
aaaa      答案是1
3 5
aaa!       答案是2
3  10
aaaaa    答案是1
3 10
aaa!aaa   答案是3
3 10
aaa!aa   答案是3

如果还有什么不明白的,留言吧……

其实这个题难就难在不懂题目背景,太长了,不愿意读啊!  而单纯的从这一句话中是很难明白的!
SMS message which consists of latin letters and spaces only can be up to M characters long while the length of SMS message which consists of any characters is limited by N characters.



代码:
思路,连个变量分别统计不同字数数目,达到上面,ans++;  计数变量归0,问题是按照那种数目限制呢?  bo帮你忙,bo=1表示有特殊字符,反之没有;  但是有一个比较尴尬的局面就是本来按照没有特殊字符计数的,但是还没达到m,忽然冒出个特殊字符来,如果加上他就超了n的限制,不加他也超了n的限制……  怎么办呢?   自己思考下:
3 5
aaa!       答案是2


#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<map>
#include<algorithm>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define inf 0x3f3f3f3f
const int N=10010;
int n,m;
string str;
bool isok(int x)
{
    if(str[x]==' '||(str[x]>='A'&&str[x]<='Z')||(str[x]>='a'&&str[x]<='z')   )return 1;
    return 0;
}
int main()
{
    /*
    cnt1,cnt2分别记录任意字符和普通字符数目(普通字符记录的是连续的,因为一旦不连续就是中间掺杂了特殊字符,就得按照特殊字符数目限制去做了)
    bo表示当前记录段内有无特殊字符,没有按照没有的要求去算;
    但是有一个小问题,就是如果特殊字符限制是3,普通字符限制是8  ,而测试数据输入时5个普通字符加一个特殊字符怎么办,不上不下的,那么前5个算一次,后面另算
    bo的状态在合适的时候改变
    */
    cin >> n>>m;
    getline(cin,str);
    getline(cin,str);
    int len=str.length();   //cout<<len<<endl;
    int cnt1=0,cnt2=0;
    //bool bo=0;
    int ans=0;
    bool bo=0;
    for(int i=0; i<=len; ++i)
    {
        if(i==len)
        {
            if(cnt1)ans++;
            break;
        }
        cnt1++;///记录任意字符

        if(isok(i))cnt2++;///记录连续的普通字符
        else  {cnt2=0;bo=1;}


        if(bo)
        {///如果有特殊字符,,那么就按照特殊字符的要求做
            if(cnt1==n)
            {
                 ans++;
                 cnt1=cnt2=0;bo=0;
            }else if(cnt1>n)
            {///这里很关键,什么情况下回超呢?  就是本来是按照一般字符处理,可是忽然多了一个特殊字符,加上这个特殊字符挺尴尬,于是就按照前面的算一次,后面的这个算另外一次
                ans++;
                cnt1=cnt2=0;bo=0;i--;
            }

        }
        else
        {///如果没有特殊字符,那么就按照一般字符数目限制去做
            if(cnt2==m)
            {
                ans++;
                cnt1=cnt2=0;bo=0;
            }
        }



    }
    cout<<ans<<endl;



}

1427. SMS

Time limit: 0.5 second
Memory limit: 64 MB

Background

Mobile technologies are going to become a part of our life. So many times you have read this sentence in advertisements and magazine articles. So many times you have heard it from fattened IT corporations presidents who grab money of deceived investors and from managers of mobile phones shops who try to sell useless smartphones at the cost of $500 a piece... Sleep tight. The age of mobility has not begun yet. Believe me, you will feel when it comes to life.
One day it will be felt by the millions of people who would find their mobile phones full of dozens of SMS messages offering sweets with swastika, courses of american Russian, services of famous charlatan Ilya German and participation in forthcoming contests on Timus Online Judge. Unfortunately the history will not keep the name of one modest programmer who was in the very origin of new age technology which will be known soon as SMS-spam. But I will say something else. This programmer is you.

Problem

SMS-spam is a promising technology of mass delivery of text advertisements by means of SMS messages. Very convenient, very effective, very easy. Not so easy, however. The problem is the length of one SMS message is limited while advertisements are usually rather long. Fortunately, an advertisement can be divided into several parts, and each part will be sent as a separate SMS message.
But here greedy mobile operators enter the game, because they also want to get some money. Their acquisitiveness is expressed in the fact that each delivered SMS message must be paid for. So an advertisement should be delivered to a thankful recipient by means of minimal number of SMS messages.
And the last thing. Quirky mobile operators have invented an amusing feature for people who want to save some money. SMS message which consists of latin letters and spaces only can be up to M characters long while the length of SMS message which consists of any characters is limited by N characters.

Input

The first line contains the integer numbers N and M (1 ≤ N ≤ M ≤ 10000). The second line contains an advertisement. The advertisement consists of from 1 to 100000 characters. Each character is either a latin letter, a space, a digit or a punctuation mark "." (full stop), "," (comma), ";" (semicolon), ":" (colon), "!" (exclamation mark), "?" (question mark), "-" (hyphen) or """ (double quotes). The advertisement is terminated by the end of line.

Output

You should output the minimal number of SMS messages required to deliver the advertisement.

Sample

input
10 15
On the 11-th of February, 2006 the contest "Timus Top Coders: First Challenge" is held!
output
8
Problem Author: Dmitry Kovalioff, Nikita Rybak, Ilya Grebnov
Problem Source: Timus Top Coders: First Challenge



timus   1427. SMS  URAL  解题报告

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值