URAL 1290. Sabotage(STL & 模拟啊)

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1290

1290. Sabotage

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.

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;
}
时间: 2024-09-29 22:18:46

URAL 1290. Sabotage(STL & 模拟啊)的相关文章

URAL 1290. Sabotage (sortings)

1290. Sabotage 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 a

HDU 4028 The time of a day STL 模拟题

暴力出奇迹.. #include<stdio.h> #include<iostream> #include<algorithm> #include<vector> #include<cmath> #include<queue> #include<set> #include<map> using namespace std; #define ll __int64 #define N 42 ll n,m,ans;

HDU 4022 Bombing STL 模拟题

手动模拟.. #include<stdio.h> #include<iostream> #include<algorithm> #include<vector> #include<cmath> #include<queue> #include<set> #include<map> using namespace std; #define N 10100 #define inf 1000000010 map<

stl+模拟 CCF2016 4 路径解析

1 // stl+模拟 CCF2016 4 路径解析 2 // 一开始题意理解错了.... 3 4 #include <iostream> 5 #include <string> 6 #include <vector> 7 using namespace std; 8 void fre() {freopen("in.txt","r",stdin);} 9 vector<string> l; 10 int main(){

【STL+模拟】UVa 506 - System Dependencies

System Dependencies  Components of computer systems often have dependencies--other components that must be installed before they will function properly. These dependencies are frequently shared by multiple components. For example, both the TELNET cli

HDU-4961 Boring Sum STL模拟

给出一个序列A,对于A里面的每个元素,左边最近的能被它整除的元素记为B序列对应位置的,右边最近的是它的整数倍的元素记为C序列对应位置,找不到的记它本身,最后算出对应位置B*C的总和. 容器模拟,按顺序扫一遍,每次如果有符合条件的取出来,即为最近的.最后把它的下标放到对应位置的容器中,然后倒序求一遍,最后求和. #include <iostream> #include <cmath> #include <cstdio> #include <cstring> #

HDU-4841 圆桌问题 STL模拟约瑟夫问题

中文题,题意一看就是卧槽,这不约瑟夫么,然后脑子一抽就用了链表写,然后果然T了,最后用Vector模拟的约瑟夫问题. #include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <queue> #include <iomanip> #include <algorithm> #include <vector>

CCF 201403-3 命令行选项 (STL模拟)

问题描述 请你写一个命令行分析程序,用以分析给定的命 令行里包含哪些选项.每个命令行由若干个字符串组成,它们之间恰好由一个空格分隔.这些字符串中的第一个为该命令行工具的名字,由小写字母组成,你的程序 不用对它进行处理.在工具名字之后可能会包含若干选项,然后可能会包含一 些不是选项的参数. 选项有两类:带参数的选项和不带参数的选项.一个合法的无参数选项的形式是一个减号后面跟单个小写字母,如"-a" 或"-b".而带参数选项则由两个由空格分隔的字符串构成,前者的格式要求

CCF 201509-3 模板生成系统 (STL+模拟)

问题描述 成成最近在搭建一个网站,其中一些页面的部分内容来自数据库中不同的数据记录,但是页面的基本结构是相同的.例如,对于展示用户信息的页面,当用户为 Tom 时,网页的源代码是 而当用户为 Jerry 时,网页的源代码是 这样的例子在包含动态内容的网站中还有很多.为了简化生成网页的工作,成成觉得他需要引入一套模板生成系统. 模板是包含特殊标记的文本.成成用到的模板只包含一种特殊标记,格式为 {{ VAR }},其中 VAR 是一个变量.该标记在模板生成时会被变量 VAR 的值所替代.例如,如果