URAL 1290. Sabotage(STL & 模拟啊)
2015-03-07 10:27
471 查看
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1290
Time limit: 1.0 second
Memory limit: 64 MB
It is the seventh year of the terrible harmful Galaxy War... Leo Hao is one of the first defenders of his planet. He is lucky! He has gone through many troubles. For example, he stayed alive after the
close combat with a meklon warrior – a perfect killing machine. He lost his left leg, right eye and spent five long months in hospital. After that incident, he had to leave the army and return to the Earth.
But Leo is lucky twice! He was able to find a good job after all these terrible incidents. Now he is a leading programmer in “U.S. Robots”. He was involved into the creation of software for zero level
defense system. However, even there he was faced with interplanetary intervention! Just a few days ago it was found out that one of his co-workers is not a human! No! Physically he was a human of course, but parasitical Darloxian – agent of the most odious
race in the Galaxy, captured his mind.
Obviously, mind corrupted by Darlok agent was not able to write high-quality code. That why Leo is now reviewing his code. It’s terrible!!! It is not effective, slow, dirty and tangled. It must be rewritten!
However, Leo faced trouble during the exploration of the following function: input is the array of positive integer numbers. First, function prints quantity of numbers in the array onto a sheet of paper.
Then quantity of numbers in the array greater than 1 is printed. Then quantity of numbers greater than 2 and so on, until the function encounters zero (zero is never printed out). After that, special mechanical manipulator puts this sheet of paper into scanner,
which reads this set of numbers into memory and the described operation repeats again. After that the new paper with numbers comes out from the printer. The scanner reads these new numbers, and stores them into the array. This array is the result of the function.
Example. Input: 4 1 6.
After first stage printer prints 3 2 2 2 1 1
After second stage the result of the function will be 6 4 1
Leo feels that it can be done more effectively. Your goal is to write a program, which will be able to replace the function written by Darlok agent, and will be much faster.
25000) one per line. It is the input for the described function.
代码如下:
或者
1290. Sabotage
Time limit: 1.0 secondMemory limit: 64 MB
It is the seventh year of the terrible harmful Galaxy War... Leo Hao is one of the first defenders of his planet. He is lucky! He has gone through many troubles. For example, he stayed alive after the
close combat with a meklon warrior – a perfect killing machine. He lost his left leg, right eye and spent five long months in hospital. After that incident, he had to leave the army and return to the Earth.
But Leo is lucky twice! He was able to find a good job after all these terrible incidents. Now he is a leading programmer in “U.S. Robots”. He was involved into the creation of software for zero level
defense system. However, even there he was faced with interplanetary intervention! Just a few days ago it was found out that one of his co-workers is not a human! No! Physically he was a human of course, but parasitical Darloxian – agent of the most odious
race in the Galaxy, captured his mind.
Obviously, mind corrupted by Darlok agent was not able to write high-quality code. That why Leo is now reviewing his code. It’s terrible!!! It is not effective, slow, dirty and tangled. It must be rewritten!
However, Leo faced trouble during the exploration of the following function: input is the array of positive integer numbers. First, function prints quantity of numbers in the array onto a sheet of paper.
Then quantity of numbers in the array greater than 1 is printed. Then quantity of numbers greater than 2 and so on, until the function encounters zero (zero is never printed out). After that, special mechanical manipulator puts this sheet of paper into scanner,
which reads this set of numbers into memory and the described operation repeats again. After that the new paper with numbers comes out from the printer. The scanner reads these new numbers, and stores them into the array. This array is the result of the function.
Example. Input: 4 1 6.
After first stage printer prints 3 2 2 2 1 1
After second stage the result of the function will be 6 4 1
Leo feels that it can be done more effectively. Your goal is to write a program, which will be able to replace the function written by Darlok agent, and will be much faster.
Input
First line of input contains the number N (0 ≤ N ≤ 25000). The next N lines contain integers pi (1 ≤ pi ≤25000) one per line. It is the input for the described function.
Output
Output should contain the result of the function, written by Darlok Agent.Sample
input | output |
---|---|
3 4 1 6 | 6 4 1 |
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; int a[25017], b[25017]; int main() { int n; while(~scanf("%d",&n)) { memset(a,0,sizeof a); memset(b,0,sizeof b); for(int i = 0; i < n; i++) { scanf("%d",&a[i]); } sort(a, a+n); int num = a[n-1]; for(int i = 1; i <= num; i++) { int tt = lower_bound(a,a+n,i)-a; b[i-1] = n-tt; } sort(b, b+num); for(int i = 1; i <= b[num-1]; i++) { int tt = lower_bound(b,b+num,i)-b; printf("%d\n",num-tt); } } return 0; }
或者
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; int a[25047], b[25047]; int num; int main() { int n; while(~scanf("%d",&n)) { for(int i = 0; i < n; i++) scanf("%d", &a[i]); sort(a,a+n); for(int i = n-1; i >= 0; i--) printf("%d\n", a[i]); } return 0; }
相关文章推荐
- URAL 1762 Search for a Hiding-Place(数学·模拟)
- UVaLive 6581 && Gym 100299B What does the fox say? (模拟+STL)
- UVa 540 Team Queue (STL list&queue模拟插队)
- hdu6168-多校9&stl&模拟- Numbers
- 814-The Letter Carrier's Rounds【模拟、STL、被坑了】
- 127 - "Accordian" Patience C++中栈,STL的模拟
- 2017CCPC秦皇岛 C题Crusaders Quest&&ZOJ3983【模拟+STL】
- STL之set&multiset容器(笔记)
- STL实践(string&IO)
- STL之map&multimap容器(笔记)
- STL(shipped with VC6) Questions & Answers(四)
- STL(shipped with VC6) Questions & Answers(四)
- STL &amp; Boost 相关中文信息收集(持续更新中)
- STL(VC6) Good Q&A(五):Are Containers Thread Safe?
- STL之stack&queue容器(笔记)
- 对C++ STL iostram 中 cin.get(char* cs,int size,char c='/n') 的理解
- Control Study -> 键盘模拟鼠标(实现用键盘操作鼠标光标)(示例代码下载)
- Control Study -> 键盘模拟鼠标(实现用键盘操作鼠标光标)(示例代码下载)
- 使用" 参数化基类" 和" 成员函数指针" 模拟实现虚函数
- 不要在DEBUG模式下使用STL实现"复杂的"算法