Paper Work Cf250A

Paper Work

Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d
& %I64u

Submit Status Practice CodeForces
250A

Description

Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company‘s performance for
the last n days. We know that the main information in a day report is value ai, the company‘s
profit on the i-th day. If ai is negative, then the company suffered losses on the i-th
day.

Polycarpus should sort the daily reports into folders. Each folder should include data on the company‘s performance for several consecutive days. Of course, the information on each of the n days
should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on.

It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (ai?<?0),
he loses his temper and his wrath is terrible.

Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal.

Write a program that, given sequence ai, will print the minimum number of folders.

Input

The first line contains integer n (1?≤?n?≤?100), n is the number of
days. The second line contains a sequence of integers a1,?a2,?...,?an(|ai|?≤?100),
where ai means the company profit on the i-th day. It is possible that the company has no days
with the negative ai.

Output

Print an integer k — the required minimum number of folders. In the second line print a sequence of integers b1b2,
..., bk, where bj is the number of day reports in the j-th
folder.

If there are multiple ways to sort the reports into k days, print any of them.

Sample Input

Input

11
1 2 3 -4 -5 -6 5 -5 -6 -7 6

Output

3
5 3 3 

Input

5
0 -1 100 -1 0

Output

1
5 

题意:给出n个数,分成m堆,每堆最多只能有两个负数,求最小的堆数,并输出每堆的个数。

简单的贪心,但写起来还是把我会搞死。。。。。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;

int a[110],b[110];

int main()
{
    int n,ans;
    while (~scanf("%d",&n))
    {
        ans=0;
        int num=0;
        for (int i=0;i<n;i++)
            scanf("%d",&a[i]);
        for (int i=0;i<n;i++)
        {
            if (a[i]<0&&num<3)
                num++;
            if (num==3)
            {
                b[ans]=i;
                ans++;
                num=1;
            }
        }
//        printf("%d %d\n",ans,num);
        b[ans]=n;
        ans++;
        if (ans==0)
        {
            ans=1;
            b[0]=n;
        }
        printf("%d\n",ans);
        printf("%d",b[0]);
        if (ans>1){
        for (int i=1;i<ans;i++)
            printf(" %d",b[i]-b[i-1]);}
        printf("\n");
    }
    return 0;
}
/*
7
-1 -2 3 4 5 6 -7
8
-1 -1 -1 -1 -1 -1 -1 -1
*/
时间: 2025-01-18 11:47:22

Paper Work Cf250A的相关文章

TOJ 2944 Mussy Paper

2944.   Mussy Paper Time Limit: 2.0 Seconds   Memory Limit: 65536K    Special JudgeTotal Runs: 381   Accepted Runs: 98 A good mathematical joke is better, and better mathematics, than a dozen mediocre papers.--J E Littlewood RoBa, an undergraduate st

Paper Reading: Perceptual Generative Adversarial Networks for Small Object Detection

Perceptual Generative Adversarial Networks for Small Object Detection 2017-07-11  19:47:46   CVPR 2017 This paper use GAN to handle the issue of small object detection which is a very hard problem in general object detection. As shown in the followin

AAAI 2016 paper阅读

本篇文章调研一些感兴趣的AAAI 2016 papers.科研要多读paper!!! Learning to Generate Posters of Scientific Papers,Yuting Qiang, Yanwei Fu, Yanwen Guo, Zhi-Hua Zhou and Leonid Sigal. http://cs.nju.edu.cn/zhouzh/zhouzh.files/publication/aaai16poster.pdf 这篇paper研究从科技论文中生成海报

paper 61:计算机视觉领域的一些牛人博客,超有实力的研究机构等的网站链接

转载出处:blog.csdn.net/carson2005 以下链接是本人整理的关于计算机视觉(ComputerVision, CV)相关领域的网站链接,其中有CV牛人的主页,CV研究小组的主页,CV领域的paper,代码,CV领域的最新动态,国内的应用情况等等.打算从事这个行业或者刚入门的朋友可以多关注这些网站,多了解一些CV的具体应用.搞研究的朋友也可以从中了解到很多牛人的研究动态.招生情况等.总之,我认为,知识只有分享才能产生更大的价值,真诚希望下面的链接能对朋友们有所帮助.(1)goog

练习题目 3 Game on Paper

 Game on Paper Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Description One not particularly beautiful evening Valera got very bored. To amuse himself a little bit, he found the following game. He took a checkered whi

paper 27 :图像/视觉显著性检测技术发展情况梳理(Saliency Detection、Visual Attention)

1. 早期C. Koch与S. Ullman的研究工作. 他们提出了非常有影响力的生物启发模型. C. Koch and S. Ullman . Shifts in selective visual attention: Towards the underlying neural circuitry. Human Neurobiology, 4(4):219-227, 1985. C. Koch and T. Poggio. Predicting the Visual World: Silenc

Codeforces Round #296 (Div. 2) A. Playing with Paper

A. Playing with Paper One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular a mm ?×? b mm sheet of paper (a?>?b). Usually the first step in making an origami is making a square piece of paper from the

c.Tom and paper

Tom and paper Description There is a piece of paper in front of Tom, its length and width are integer. Tom knows the area of this paper, he wants to know the minimum perimeter of this paper. Input In the first line, there is an integer T indicates th

CSU1656: Paper of FlyBrother(后缀数组)

Description FlyBrother is a superman, therefore he is always busy saving the world. To graduate from NUDT is boring but necessary for him. Typically We need to post an paper to get Graduate Certificate, however being one superman, FlyBrother wants to