CodeForces 39B Company Income Growth
2016-02-17 23:36
375 查看
B. Company Income Growth
time limit per test
2 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output
Petya works as a PR manager for a successful Berland company BerSoft. He needs to prepare a presentation on the company income growth since
2001 (the year of its founding) till now. Petya knows that in
2001 the company income amounted to
a1 billion bourles, in
2002 — to a2 billion, ..., and in the current
(2000 + n)-th year —
an billion bourles. On the base of the information Petya decided to show in his presentation the linear progress history which is in his opinion perfect. According to a graph Petya has already made, in
the first year BerSoft company income must amount to 1 billion bourles, in the second year —
2 billion bourles etc., each following year the income increases by
1 billion bourles. Unfortunately, the real numbers are different from the perfect ones. Among the numbers
ai can even occur negative ones that are a sign of the company’s losses in some years. That is why Petya wants to ignore some data, in other words, cross some numbers
ai from the sequence and leave only some subsequence that has perfect growth.
Thus Petya has to choose a sequence of years y1,
y2, ...,
yk,so that in the year
y1 the company income amounted to
1 billion bourles, in the year y2 —
2 billion bourles etc., in accordance with the perfect growth dynamics. Help him to choose the longest such sequence.
Input
The first line contains an integer n (1 ≤ n ≤ 100). The next line contains
n integers ai ( - 100 ≤ ai ≤ 100). The number
ai determines the income of BerSoft company in the
(2000 + i)-th year. The numbers in the line are separated by spaces.
Output
Output k — the maximum possible length of a perfect sequence. In the next line output the sequence of years
y1,
y2, ..., yk. Separate the numbers by spaces. If the answer is not unique, output any. If no solution exist, output one number
0.
Sample test(s)
Input
Output
Input
Output
[/code]
time limit per test
2 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output
Petya works as a PR manager for a successful Berland company BerSoft. He needs to prepare a presentation on the company income growth since
2001 (the year of its founding) till now. Petya knows that in
2001 the company income amounted to
a1 billion bourles, in
2002 — to a2 billion, ..., and in the current
(2000 + n)-th year —
an billion bourles. On the base of the information Petya decided to show in his presentation the linear progress history which is in his opinion perfect. According to a graph Petya has already made, in
the first year BerSoft company income must amount to 1 billion bourles, in the second year —
2 billion bourles etc., each following year the income increases by
1 billion bourles. Unfortunately, the real numbers are different from the perfect ones. Among the numbers
ai can even occur negative ones that are a sign of the company’s losses in some years. That is why Petya wants to ignore some data, in other words, cross some numbers
ai from the sequence and leave only some subsequence that has perfect growth.
Thus Petya has to choose a sequence of years y1,
y2, ...,
yk,so that in the year
y1 the company income amounted to
1 billion bourles, in the year y2 —
2 billion bourles etc., in accordance with the perfect growth dynamics. Help him to choose the longest such sequence.
Input
The first line contains an integer n (1 ≤ n ≤ 100). The next line contains
n integers ai ( - 100 ≤ ai ≤ 100). The number
ai determines the income of BerSoft company in the
(2000 + i)-th year. The numbers in the line are separated by spaces.
Output
Output k — the maximum possible length of a perfect sequence. In the next line output the sequence of years
y1,
y2, ..., yk. Separate the numbers by spaces. If the answer is not unique, output any. If no solution exist, output one number
0.
Sample test(s)
Input
10 -2 1 1 3 2 3 4 -10 -2 5
Output
5 2002 2005 2006 2007 2010
Input
3 -1 -2 -3
Output
0 注意年份是从小到大排列。 [code]#include<iostream> using namespace std; struct income_amounted{ int income; int year; }company[110]; int main(){ int n,k,t,flag,num[110]; while(cin>>n){ k=t=flag=0; for(int i=1;i<=n;i++){ cin>>company[i].income; company[i].year=i; } for(int i=1;;i++){ flag=0; for(int j=t+1;j<=n;j++){ if(company[j].income==i){ flag=1; num[k]=company[j].year; k++; t=j; break; } } if(flag==0){ break; } } cout<<k<<endl; for(int i=0;i<k;i++){ if(i!=(k-1)){ cout<<num[i]+2000<<" "; } else{ cout<<num[i]+2000<<endl; } } } return 0; }
[/code]
相关文章推荐
- UVA-10118 Free Candies (DP、记忆化搜索)
- 1083. List Grades (25)
- Apache 编译 --with-apr parameter is incorrect 错误
- POJ 2387 Til the Cows Come Home(dij+邻接矩阵)
- 未来趋势
- 一个错误
- a类、b类、c类地址
- 老王学linux-centos6.7RHCS
- iOS学习----------图片的简单处理(1)
- LBS-Object C 定位,地图,导航
- NSString的八条实用技巧
- ASM:《X86汇编语言-从实模式到保护模式》1-4章:处理器,内存和硬盘基础
- HDU 2544 最短路(dijkstra+邻接矩阵)
- 一个实现了APP内部集中式通知中心,简化通知管理,简化代码逻辑和debug
- 传智播客168期JavaEE就业班(第八天 WEB简介 Tomcat)
- 【设计模式】组合模式
- springmvc应用程序使用maven部署到tomcat中时产生的异常的解决(javax/servlet/ServletContext&SpringServletContainerInitializer->javax.servlet.ServletContainerInitializer)
- 关于相对路径和绝对路径
- 2016/2/17 codes
- PHP——投票