quarta-feira, 24 de outubro de 2018

URI PROBLEMA 1471 - Mergulho SOLUÇÃO EM C

URI Online Judge | 1471

Mergulho

Maratona de Programação da SBC  Brasil
Timelimit: 1
O recente terremoto em Nlogônia não chegou a afetar muito as edificações da capital, principal epicentro do abalo. Mas os cientistas detectaram que o principal dique de contenção teve um dano significativo na sua parte subterrânea que, se não for consertado rapidamente, pode causar o seu desmoronamento, com a consequente inundação de toda a capital.
O conserto deve ser feito por mergulhadores, a uma grande profundidade, em condições extremamente difíceis e perigosas. Mas como é a sobrevivência da própria cidade que está em jogo, seus moradores acudiram em grande número como voluntários para essa perigosa missão.
Como é tradicional em missões perigosas, cada mergulhador recebeu no início do mergulho uma pequena placa com um número de identificação. Ao terminar o mergulho, os voluntários devolviam a placa de identificação, colocando-a em um repositório.
O dique voltou a ser seguro, mas aparentemente alguns voluntários não voltaram do mergulho. Você foi contratado para a penosa tarefa de, dadas as placas colocadas no repositório, determinar quais voluntários perderam a vida salvando a cidade.

Entrada

A entrada contém vários casos de teste e termina com EOF. Cada caso de teste é composto de duas linhas. A primeira linha contém dois inteiros N e ( 1 ≤ R ≤ N ≤ 104), indicando respectivamente o número de voluntários que mergulhou e o número de voluntários que retornou do mergulho. Os voluntários são identificados por números de 1 a N. A segunda linha da entrada contém R inteiros, indicando os voluntários que retornaram do mergulho (ao menos um voluntário retorna do mergulho).

Saída

Seu programa deve produzir uma única linha para cada caso de teste, contendo os identificadores dos voluntários que não retornaram do mergulho, na ordem crescente de suas identificações. Deixe um espaço em branco após cada identificador (note que isto significa que deve haver um espaço em branco também após o último identificador). Se todos os voluntários retornaram do mergulho, imprima apenas o caractere ‘*’ (asterisco).



URI Online Judge | 1471

Dangerous Dive

Maratona de Programação da SBC  Brasil
Timelimit: 1
The recent earthquake in Nlogonia did not affect too much the buildings in the capital, which was at the epicenter of the quake. But the scientists found that it affected the dike wall, which now has a significant structural failure in its underground part that, if not repaired quickly, can cause the
collapse of the dike, with the consequent flooding the whole capital.
The repair must be done by divers, at a large depth, under extremely difficult and dangerous conditions. But since the survival of the city is at stake, its residents came out in large numbers to volunteer for this dangerous mission.
As is traditional in dangerous missions, each diver received at the start of his/her mission a small card with an identification number. At the end of their mission, the volunteers returned the nameplate, placing it in a repository.
The dike is safe again, but unfortunately it seems that some volunteers did not return from their missions. You were hired for the grueling task of, given the plates placed in the repository, determine which volunteers lost their lives to save the city.

Input

The input contains several test cases and ends with EOF. Each test case is composed of two lines. The first line contains two integers N and ( 1 ≤ R ≤ N ≤ 104), indicating respectively the number of volunteers that went to the mission and the number of volunteers that returned from the mission. Volunteers are identified by numbers from 1 to N. The second line contains R integers, indicating the volunteers which returned from the mission (at least one volunteer returned).

Output

For each test case your program must produce a single line containing the identifiers of the volunteers who did not return from their missions, in ascending order of their identifications. Leave a blank space after each identifier (notice that, therefore, there must be a blank space after the last identifier in the line). If every volunteer returned, the line must contain a single character ‘*’ (asterisc).



#include <stdio.h>

#define QUANTIDADE_MERGULHADORES 10001

int main (void) {
    int foram, voltaram,
        mergulhadoresQueVoltaram[QUANTIDADE_MERGULHADORES],
        i,
        mergulhadorQueVoltou;

    for (i = 0; i < QUANTIDADE_MERGULHADORES; i++) {
        mergulhadoresQueVoltaram[i] = 0;
    }

    while (scanf("%d %d", &foram, &voltaram) == 2) {
        if (foram == voltaram) {
            // clear
            for (i = 1; i <= voltaram; i++) { scanf("%d", &mergulhadorQueVoltou); }

            printf("*");
        }
        else {
            for (i = 1; i <= voltaram; i++) {
                scanf("%d", &mergulhadorQueVoltou);

                // set
                mergulhadoresQueVoltaram[mergulhadorQueVoltou] = 1;
            }

            for (i = 1; i <= foram; i++) {
                if (!mergulhadoresQueVoltaram[i]) {
                    printf("%d ", i);
                }

                // reset
                mergulhadoresQueVoltaram[i] = 0;
            }
        }

        printf("\n");
    }

    return 0;
}

Nenhum comentário:

Postar um comentário

URI PROBLEMA 1133 - Resto da Divisão SOLUÇÃO EM C

URI Online Judge | 1133 Resto da Divisão Adaptado por Neilor Tonin, URI   Brasil Timelimit: 1 Escreva um programa que leia 2 valo...