Вы находитесь на странице: 1из 3

FILA Uma fila (= queue) uma estrutura linear sujeita s operaes de insero e remoo.

. Essas operaes obedecem poltica FIFO (= first in, first out): o objeto removido sempre o que foi inserido h mais tempo. Diz-se que uma das extremidades de uma fila o incio ou cabea (= head) e a outra extremidade o fim ou cauda (= tail) da fila. Objetos so inseridos no fim da fila e so removidos do incio da fila. IMPLEMENTAO USANDO VETOR #define MAXN 1000 typedef struct{ int v[MAXN]; int fi,ff; }TFila; void nova(TFila * fila){ fila->fi = 0; fila->ff = 0; } void enfila(TFila *fila,int x){ fila->v[fila->ff++] = x; } int desenfila(TFila *fila){ return fila->v[fila->fi++]; } int esta_vazia(TFila fila){ return fila.fi == fila.ff; } void mostra(TFila fila){ printf("fi %d ff %d\n",fila.fi,fila.ff); } int main(){ TFila fila; nova(&fila); enfila(&fila,2); enfila(&fila,3); while(!esta_vazia(fila)){ printf("%d\n",desenfila(&fila)); mostra(fila); }

return 0; } IMPLEMENTAO em C++ #include <iostream> #include <queue> #include <stdlib.h> using namespace std; queue <int> fila; int main(){ fila = queue <int> (); //queue no tem o mtodo clear (limpar) fila.push(2);//mtodo push coloca um elmento na fila fila.push(3); fila.push(4); cout << fila.size() << endl; //mtodo size retorna o tamanho da fila cout << fila.back() << endl; // mtodo back retorna a referencia para o ultimo da fila while( !fila.empty() ){//mtodo empty testa se a fila est vazia cout << fila.front() << endl;//mtodo front retorna o primeiro elemento da fila fila.pop(); //mtodo pop retira o primeiro elemento da fila } system("PAUSE"); } IMPLEMENTAO EM JAVA import java.util.Queue; import java.util.LinkedList;

import java.util.Scanner;
public class FilaDemo { public static void main(String args[] ){ int n; Queue<Integer> fila = new LinkedList<Integer>();

Scanner scan = new Scanner( System.in ); n = scan.nextInt();


fila.add(2); fila.add(3); fila.add(4); while( !fila.isEmpty() ){ System.out.println( fila.remove() ); } } }

10935 - Throwing cards away I Time limit: 3.000 seconds

Given is an ordered deck of n cards numbered 1 to n with card 1 at the top and card n at the bottom. The following operation is performed as long as there are at least two cards in the deck: Throw away the top card and move the card that is now on the top of the deck to the bottom of the deck. Your task is to find the sequence of discarded cards and the last, remaining card. Each line of input (except the last) contains a number n 50. The last line contains 0 and this line should not be processed. For each number from the input produce two lines of output. The first line presents the sequence of discarded cards, the second line reports the last remaining card. No line will have leading or trailing spaces. See the sample for the expected format. Sample input 7 19 10 6 0 Output for sample input Discarded cards: 1, Remaining card: 6 Discarded cards: 1, Remaining card: 6 Discarded cards: 1, Remaining card: 4 Discarded cards: 1, Remaining card: 4

3, 5, 7, 4, 2 3, 5, 7, 9, 11, 13, 15, 17, 19, 4, 8, 12, 16, 2, 10, 18, 14 3, 5, 7, 9, 2, 6, 10, 8 3, 5, 2, 6

10940 - Throwing cards away II 151 - Power Crisis Time limit: 3.000 seconds During the power crisis in New Zealand this winter (caused by a shortage of rain and hence low levels in the hydro dams), a contingency scheme was developed to turn off the power to areas of the country in a systematic, totally fair, manner. The country was divided up into N regions (Auckland was region number 1, and Wellington number 13). A number, m, would be picked `at random', and the power would first be turned off in region 1 (clearly the fairest starting point) and then in every m'th region after that, wrapping around to 1 after N, and ignoring regions already turned off. For example, if N = 17 and m = 5, power would be turned off to the regions in the order:1,6,11,16,5,12,2,9,17,10,4,15,14,3,8,13,7. The problem is that it is clearly fairest to turn off Wellington last (after all, that is where the Electricity headquarters are), so for a given N, the `random' number m needs to be carefully chosen so that region 13 is the last region selected. Write a program that will read in the number of regions and then determine the smallest number m that will ensure that Wellington (region 13) can function while the rest of the country is blacked out. Input and Output

Input will consist of a series of lines, each line containing the number of regions (N) with terminated by a line consisting of a single 0.

. The file will be

Output will consist of a series of lines, one for each line of the input. Each line will consist of the number m according to the above scheme. Sample input 17 0 Sample output 7

440 - Eeny Meeny Moo

Вам также может понравиться

  • Manual Básico de Fanuc
    Manual Básico de Fanuc
    Документ50 страниц
    Manual Básico de Fanuc
    Marcos Becerra
    100% (11)
  • MBB2017 201a252
    MBB2017 201a252
    Документ52 страницы
    MBB2017 201a252
    Vitoria Carvalho
    0% (1)
  • Guia Do Usuário - Shop Control 8
    Guia Do Usuário - Shop Control 8
    Документ357 страниц
    Guia Do Usuário - Shop Control 8
    Ayrton Medeiros
    100% (2)
  • Diagrama Elétrico 2144G
    Diagrama Elétrico 2144G
    Документ189 страниц
    Diagrama Elétrico 2144G
    Joaci Pacheco
    100% (1)
  • Trabalho Bombas Hidraulicas
    Trabalho Bombas Hidraulicas
    Документ11 страниц
    Trabalho Bombas Hidraulicas
    Alexandre Panda
    50% (2)
  • RESOLU+ç+âO CONFEA 335 89 (MODALIDADE ENGENHARIA)
    RESOLU+ç+âO CONFEA 335 89 (MODALIDADE ENGENHARIA)
    Документ5 страниц
    RESOLU+ç+âO CONFEA 335 89 (MODALIDADE ENGENHARIA)
    Flávio Henrique
    Оценок пока нет
  • Como Fazer Pao 1 C
    Como Fazer Pao 1 C
    Документ2 страницы
    Como Fazer Pao 1 C
    bsdmkx
    Оценок пока нет
  • Concurso Caxias Do Sul
    Concurso Caxias Do Sul
    Документ2 страницы
    Concurso Caxias Do Sul
    bsdmkx
    Оценок пока нет
  • Como Fazer Pao 1 C
    Como Fazer Pao 1 C
    Документ2 страницы
    Como Fazer Pao 1 C
    bsdmkx
    Оценок пока нет
  • WWW 22222
    WWW 22222
    Документ2 страницы
    WWW 22222
    bsdmkx
    Оценок пока нет
  • Sdsadsaas
    Sdsadsaas
    Документ2 страницы
    Sdsadsaas
    bsdmkx
    Оценок пока нет
  • Concurso Caxias Do Sul
    Concurso Caxias Do Sul
    Документ2 страницы
    Concurso Caxias Do Sul
    bsdmkx
    Оценок пока нет
  • Como Fazer Pao
    Como Fazer Pao
    Документ2 страницы
    Como Fazer Pao
    bsdmkx
    Оценок пока нет
  • Como Fazer Pao
    Como Fazer Pao
    Документ2 страницы
    Como Fazer Pao
    bsdmkx
    Оценок пока нет
  • Sdsadsaas
    Sdsadsaas
    Документ2 страницы
    Sdsadsaas
    bsdmkx
    Оценок пока нет
  • Como Fazer Pao
    Como Fazer Pao
    Документ2 страницы
    Como Fazer Pao
    bsdmkx
    Оценок пока нет
  • Como Fazer Pao
    Como Fazer Pao
    Документ2 страницы
    Como Fazer Pao
    bsdmkx
    Оценок пока нет
  • CC5
    CC5
    Документ2 страницы
    CC5
    bsdmkx
    Оценок пока нет
  • Como Fazer Pao
    Como Fazer Pao
    Документ2 страницы
    Como Fazer Pao
    bsdmkx
    Оценок пока нет
  • Como Fazer Pao
    Como Fazer Pao
    Документ2 страницы
    Como Fazer Pao
    bsdmkx
    Оценок пока нет
  • JHGF
    JHGF
    Документ3 страницы
    JHGF
    bsdmkx
    Оценок пока нет
  • Como Fazer Pao
    Como Fazer Pao
    Документ2 страницы
    Como Fazer Pao
    bsdmkx
    Оценок пока нет
  • Como Fazer Pao
    Como Fazer Pao
    Документ2 страницы
    Como Fazer Pao
    bsdmkx
    Оценок пока нет
  • JJJ
    JJJ
    Документ2 страницы
    JJJ
    bsdmkx
    Оценок пока нет
  • Remover Protecao Excel
    Remover Protecao Excel
    Документ7 страниц
    Remover Protecao Excel
    Teddy Parker da Silva
    Оценок пока нет
  • Textto 01
    Textto 01
    Документ4 страницы
    Textto 01
    bsdmkx
    Оценок пока нет
  • GG
    GG
    Документ1 страница
    GG
    bsdmkx
    Оценок пока нет
  • CC7
    CC7
    Документ2 страницы
    CC7
    bsdmkx
    Оценок пока нет
  • CC6
    CC6
    Документ1 страница
    CC6
    bsdmkx
    Оценок пока нет
  • Como Fazer Pao
    Como Fazer Pao
    Документ2 страницы
    Como Fazer Pao
    bsdmkx
    Оценок пока нет
  • JDJDJDJD
    JDJDJDJD
    Документ3 страницы
    JDJDJDJD
    bsdmkx
    Оценок пока нет
  • CC3
    CC3
    Документ1 страница
    CC3
    bsdmkx
    Оценок пока нет
  • CC4
    CC4
    Документ1 страница
    CC4
    bsdmkx
    Оценок пока нет
  • CCC
    CCC
    Документ1 страница
    CCC
    bsdmkx
    Оценок пока нет
  • CC2
    CC2
    Документ2 страницы
    CC2
    bsdmkx
    Оценок пока нет
  • CC1
    CC1
    Документ1 страница
    CC1
    bsdmkx
    Оценок пока нет
  • Capacitância e Dielétricos
    Capacitância e Dielétricos
    Документ21 страница
    Capacitância e Dielétricos
    Lara Viana Aires
    100% (1)
  • Como Determinar o Coeficiente de Recalque Vertical - QiSuporte
    Como Determinar o Coeficiente de Recalque Vertical - QiSuporte
    Документ5 страниц
    Como Determinar o Coeficiente de Recalque Vertical - QiSuporte
    Naldinho Monteiro
    Оценок пока нет
  • PlasmaXGas PDF
    PlasmaXGas PDF
    Документ32 страницы
    PlasmaXGas PDF
    desetek
    Оценок пока нет
  • Report
    Report
    Документ105 страниц
    Report
    Hedion Fernando Padilha
    Оценок пока нет
  • Silo Pulmão
    Silo Pulmão
    Документ1 страница
    Silo Pulmão
    Felipe Flores
    Оценок пока нет
  • Catalogo Tecnico Caixa Dagua Brasilit
    Catalogo Tecnico Caixa Dagua Brasilit
    Документ8 страниц
    Catalogo Tecnico Caixa Dagua Brasilit
    Flávio Alves
    Оценок пока нет
  • Curriculum Vitae Helder
    Curriculum Vitae Helder
    Документ3 страницы
    Curriculum Vitae Helder
    helder_santos2
    Оценок пока нет
  • S 160-GJ PDF
    S 160-GJ PDF
    Документ3 страницы
    S 160-GJ PDF
    Cristiano Farias
    Оценок пока нет
  • Aplicação de Rasterização de Recta Usando o Algoritmo DDA
    Aplicação de Rasterização de Recta Usando o Algoritmo DDA
    Документ12 страниц
    Aplicação de Rasterização de Recta Usando o Algoritmo DDA
    Guto Condela
    Оценок пока нет
  • TPF3 Novo
    TPF3 Novo
    Документ2 страницы
    TPF3 Novo
    mquaiotti
    Оценок пока нет
  • Lista de Alarmes e Parâmetros AGC4
    Lista de Alarmes e Parâmetros AGC4
    Документ205 страниц
    Lista de Alarmes e Parâmetros AGC4
    Ricardo Nunes Pereira Junior
    100% (1)
  • Prática 6 Osciloscopio, Gerador de Sinais e Multímetro
    Prática 6 Osciloscopio, Gerador de Sinais e Multímetro
    Документ5 страниц
    Prática 6 Osciloscopio, Gerador de Sinais e Multímetro
    AbraãoBorges
    Оценок пока нет
  • Instrução de Orçamento Blender
    Instrução de Orçamento Blender
    Документ8 страниц
    Instrução de Orçamento Blender
    Leandro Luz Costa Costa
    Оценок пока нет
  • BT - Hammerite BR 07.2013
    BT - Hammerite BR 07.2013
    Документ2 страницы
    BT - Hammerite BR 07.2013
    Bruno R
    Оценок пока нет
  • Aula 08 Programação FANUC - Fresamento CNC
    Aula 08 Programação FANUC - Fresamento CNC
    Документ12 страниц
    Aula 08 Programação FANUC - Fresamento CNC
    Junior Guedes
    Оценок пока нет
  • Documento Técnico: Consórcio Monotrilho Integração Consórcio Outec / Pron
    Documento Técnico: Consórcio Monotrilho Integração Consórcio Outec / Pron
    Документ88 страниц
    Documento Técnico: Consórcio Monotrilho Integração Consórcio Outec / Pron
    Anderson
    Оценок пока нет
  • Apostila Proteção Respiratória
    Apostila Proteção Respiratória
    Документ9 страниц
    Apostila Proteção Respiratória
    Sandro Lucio de Oliveira
    Оценок пока нет
  • Fire 2002 Bosch
    Fire 2002 Bosch
    Документ1 страница
    Fire 2002 Bosch
    Ronaldo Júniôr
    Оценок пока нет
  • ( (Catalogo HAMP 2019) )
    ( (Catalogo HAMP 2019) )
    Документ2 страницы
    ( (Catalogo HAMP 2019) )
    Jokar Motos Peças
    Оценок пока нет
  • Envio de Email Com Anexos Utilizando PL-SQL e JSP
    Envio de Email Com Anexos Utilizando PL-SQL e JSP
    Документ6 страниц
    Envio de Email Com Anexos Utilizando PL-SQL e JSP
    Megan Sloan Gomes
    Оценок пока нет
  • Eh 02
    Eh 02
    Документ7 страниц
    Eh 02
    SJE Monitoramento
    Оценок пока нет
  • Mirella Okumura Revisada
    Mirella Okumura Revisada
    Документ54 страницы
    Mirella Okumura Revisada
    Misael Albuquerque Lira
    Оценок пока нет
  • Aula 5 - 5W 2H + GUT PDF
    Aula 5 - 5W 2H + GUT PDF
    Документ19 страниц
    Aula 5 - 5W 2H + GUT PDF
    Vinícius Soares
    Оценок пока нет
  • Lista
    Lista
    Документ2 страницы
    Lista
    Venha Relaxar
    Оценок пока нет