Thứ Hai, 26 tháng 11, 2012

Problem Paper Work

Link: http://codeforces.com/problemset/problem/250/A

A. Paper Work
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as ndays. Right now his task is to make a series of reports about the company's performance for the last ndays. 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 test(s)
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 
Note
Here goes a way to sort the reports from the first sample into three folders:
1 2 3 -4 -5 | -6 5 -5 | -6 -7 6
In the second sample you can put all five reports in one folder.


Thuật toán: Cài đặt theo mô phỏng của bài toán.
Chú ý một số trường hợp biên như đến cuối dãy,

Code:

/*
Coder : Nguyen Duc Tam
*/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<vector>
#include<utility>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<stack>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<ctime>

using namespace std;

#define REP(i, start, end, step) for(int i = start; i < end; i += step)
#define DOWN(i, start, end, step) for(int i = start; i > end; i -= step)
#define FOR(it,c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())
#define X first
#define Y second

#define L(x,i) ((x) << (i))
#define R(x,i) ((x) >> (i))
#define AND(a,b) ((a) & (b))
#define OR(a,b) ((a) | (b))
#define XOR(a,b) ((a) ^ (b))
#define NOT(a) (~(a))
#define SB(x,i) (OR((x), L(1, (i)))) // x | 1 << i
#define CB(x,i) (AND((x),NOT(L(1,(i))))) // x & ~(1 << i)
#define TB(x,i) (AND((x), L(1,(i)))) // x & (1 << i)

#define FILL(a,val) memset(a,val,sizeof(a));
#define INIT(a,l,r,val) REP(i,l,r,1) (a)[i] = val;
#define DIG(c) (int)((c) - '0')
#define CHR(c) (char)((c) + '0')
#define LOW(c) (char)((c) + 32)
#define UPP(c) (char)((c) - 32)

#define EPS 1e-7
#define OO 1000000005
#define N 100005

const int DAY[13] = {-1,31,29,31,30,31,30,31,31,30,31,30,31};
const int dx4[4] = {};
const int dy4[4] = {};
const int dx8[8] = {};
const int dy8[8] = {};


typedef pair<int,int> II;
typedef pair<II,int> D;
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned char UC;

vector<int>::iterator it, low, up; // using FOR, lower_bound, upper_bound
pair<vector<int>,vector<int> > bound; // using function equal_range(first, last, x)

int n,a[105], temp = 0, cur = 0;
vector<int> res;
int main()
{
#define Off  true
if(Off)
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
}
cin >> n;
REP(i,0,n,1)
{
cin >> a[i];
cur++;
if(a[i] < 0)
temp++;
if(temp == 3 || i == n -1)
{
if(i == n - 1 && temp < 3)
{
res.push_back(cur);
}
else
if(temp == 3 && i == n - 1)
{
res.push_back(cur - 1);
res.push_back(1);
}
else
{
cur--;
res.push_back(cur);
cur = 1;
temp = 1;
}
}
}
cout << res.size() << endl;
int out = (int)res.size();
REP(i,0,out,1)
cout << res[i] << " ";
cout << endl;

return 0;
}





Không có nhận xét nào:

Đăng nhận xét