'분류 전체보기'에 해당되는 글 107건

  1. 2009.06.02 :: [Accept] 10099 - The Tourist Guide
  2. 2009.06.02 :: [Accept] 10099 - The Tourist Guide
  3. 2009.06.02 :: [Time Limit] 10099 - The Tourist Guide
  4. 2009.06.02 :: [Accept] 10004 - Bicoloring problem
  5. 2009.06.02 :: [Accept] 100 - The 3n+1 problem
  6. 2009.06.02 :: 10006 - Carmichael Numbers
  7. 2009.06.02 :: 850 - Crypt Kicker II
  8. 2009.06.02 :: 10039 - Railroads
  9. 2009.06.02 :: 10110 - Light, more light
  10. 2009.06.02 :: 10132 - File Fragmentation
ACM 2009. 6. 2. 21:02
반응형

This code is also another co-worker's source.
He makes it even if he didn't use any algorithm.
He made his own way that he delete the edge which is not the answer

----------------------------------------------------------------------------------------------

#include

#define MAXV            100
#define MAXDEGREE       100

typedef struct {
        unsigned int edges[MAXV+1][MAXV+1];
        unsigned int nverticies;
        unsigned int nedges;
} graph;

graph g;

typedef struct {
        unsigned int x;
        unsigned int y;
        unsigned int value;
} minSt;

minSt minList[10000];
unsigned int minCnt;

int map[100];
int cnt;

void init_graph()
{
        memset(&g, 0, sizeof(graph));
}

void set_edges(int i)
{
        g.nedges = i;
}

void set_verticies(int i)
{
        g.nverticies = i;
}

void set_edge(int x, int y,int weight)
{
        g.edges[x][y] = weight;
        g.edges[y][x] = weight;

        minList[minCnt].x = x;
        minList[minCnt].y = y;
        minList[minCnt++].value = weight;
}

void sort_min()
{
        minSt tmp;
        int i,j;

        for ( i = 0 ; i < minCnt ; i++ ) {
                for ( j = i ; j < minCnt ; j++ ) {
                        if ( minList[i].value > minList[j].value ) {
                                tmp = minList[i];
                                minList[i] = minList[j];
                                minList[j] = tmp;
                        }
                }
        }
#if 0
        for ( i = 0 ; i < minCnt ; i++ ) {
                printf("x(%d) y(%d) weight(%d)\n",minList[i].x, minList[i].y, minList[i].value);
        }
#endif
}

void print_graph()
{
        int i,j;
        printf("==========================\n");
        for ( i = 1 ; i <= g.nverticies ; i++ ) {
                for ( j = 1 ; j <= g.nverticies ; j++ ) {
                        printf("%3d ",g.edges[i][j]);
                }
                printf("\n");
        }
}

unsigned int ConnMap[101][101];

int isConnected2()
{
        int i,j,k;

        memcpy(ConnMap, g.edges, sizeof(ConnMap));

        for ( i = 1 ; i <= g.nverticies ; i++ ) {
                for ( j = 1 ; j <= g.nverticies ; j++ ) {
                        if ( i == j )
                                continue;
                        for ( k = 1 ; k <= g.nverticies ; k++ ) {
                                if ( j == k )
                                        continue;
                                if ( i == k )
                                        continue;
                                if ( ConnMap[i][j] > 0 && ConnMap[j][k] > 0 ) {
                                        ConnMap[i][j] = 1;
                                        ConnMap[j][i] = 1;

                                        ConnMap[j][k] = 1;
                                        ConnMap[k][j] = 1;

                                        ConnMap[i][k] = 1;
                                        ConnMap[k][i] = 1;
                                }
                        }
                }
        }

#if 0
        printf("==========================\n");
        for ( i = 1 ; i <= g.nverticies ; i++ ) {
                for ( j = 1 ; j <= g.nverticies ; j++ ) {
                        printf("%3d ",ConnMap[i][j]);
                }
                printf("\n");
        }
        exit(0);
#endif

}

int isConnected(int start,int end)
{
        register unsigned int i,j;
        register unsigned int check=0;

        if ( start == end )
                return 1;

#if 1
        if ( g.edges[start][end] > 0 ) {
                return 1;
        }
#endif

        for ( i = 1 ; i <= g.nverticies ; i++ ) {
                if ( i == start )
                        continue;

                check = 0;
                for ( j = 0 ; j < cnt ; j++ ) {
                        if ( map[j] == i ) {
                                check=1;
                                break;
                        }
                }
                if ( check == 1 )
                        continue;

                if ( g.edges[start][i] > 0) {
                        map[cnt]=start;
                        cnt++;
                        if (isConnected(i,end) == 1 ) {
                                return 1;
                        }
                }
        }
        return 0;
}


void del_edge(int x,int y)
{
        g.edges[x][y] = 0;
        g.edges[y][x] = 0;
}

int main()
{
        int edge;
        int vert;
        int x,y;
        int i,weight;
        int start, end, people;
        int min;
        int scenario=1;

        while(1) {
                init_graph();
                scanf("%d %d",&vert,&edge);
                if ( vert == 0 )
                        break;
                if ( vert < 1 || vert > 100 )
                        continue;

                set_verticies(vert);
                set_edges(edge);

                for ( i = 0 ; i < edge ; i++ ) {
                        scanf("%d %d %d",&x,&y,&weight);
                        set_edge(x,y,weight);
                }
                scanf("%d %d %d",&start,&end,&people);

                sort_min();

                cnt = 0;
                i = 0;

                while ( isConnected(start,end)) {
#if 0
                while ( 1 ) {
                        isConnected2();
                        if ( ConnMap[start][end] == 0 )
                                break;
#endif

                        cnt = 0;
                        min = minList[i].value;
                        del_edge(minList[i].x,minList[i].y);
                        i++;
                }

                if ( people % (min-1 ) == 0 )
                        min = people/(min-1);
                else
                        min = people/(min-1) + 1;

                printf("Scenario #%d\n",scenario++);
                printf("Minimum Number of Trips = %d\n\n",min);

                minCnt = 0;

                fflush(stdin);
        }

        return 0;
}


#if 0
int find_min(int *x, int *y)
{
        int i,j;
        int min=99999;
        int a;

        for ( i = 1 ; i <= g.nverticies ; i++ ) {
                for ( j = 1 ; j <= g.nverticies ; j++ ) {
                        if ( g.edges[i][j] > 0 && g.edges[i][j] < min ){
                                min = g.edges[i][j];
                                *x = i;
                                *y = j;
                        }
                }
        }
        return min;
}
#endif

반응형

'ACM' 카테고리의 다른 글

[Accept] 850 Crypt Kicker II  (0) 2009.06.02
[Accept] 10132 File Fragmentation  (0) 2009.06.02
[Accept] 10099 - The Tourist Guide  (0) 2009.06.02
[Time Limit] 10099 - The Tourist Guide  (0) 2009.06.02
[Accept] 10004 - Bicoloring problem  (0) 2009.06.02
posted by ssuk1010
:
ACM 2009. 6. 2. 20:56
반응형

Unfortunately, I didn't get accept from Judge Server.
This code is one of my co-worker's source.
He used Dynamic Programming.
I should study that algorithm.

----------------------------------------------------------------------------------------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <stdio.h>
int g_cities[101][101];
 
#define MIN(a,b) (a>b?b:a)
 
int search_min_trips(int start, int end, int num_cities)
{
    int i, j, k;
    int max = 0, min;
    for (i = 1; i <= num_cities; i++) {
    for (j = 1; j <= num_cities; j++) {
    for (k = 1; k <= num_cities; k++) {
        min = MIN(g_cities[i][k], g_cities[k][j]);
        if (g_cities[i][j] < min)
            g_cities[i][j] = g_cities[j][i] = min;
    }}} 
    return g_cities[start][end];
}   
 
int main()
{
    int i, cnt = 0;
    int num_cities;
    int num_roads;
    int num_passengers;
    int start, end;
    int city1, city2, cap;
    int max_cap;
    
    while (scanf("%d %d", &num_cities, &num_roads) != 1 && num_cities != 0 && num_roads != 0) {
        memset(g_cities, 0x00, sizeof(g_cities));
        for (i = 0; i < num_roads; i++) {
            scanf("%d %d %d", &city1, &city2, &cap);
            g_cities[city1][city2] =  
            g_cities[city2][city1] = cap;
        }   
        scanf("%d %d %d", &start, &end, &num_passengers);
        max_cap = search_min_trips(start, end, num_cities) - 1;
        printf("Scenario #%d\n", ++cnt);
        printf("Minimum Number of Trips = %d\n\n", num_passengers / max_cap + (num_passengers % max_cap == 0 ? 0 : 1));
    }   
    return 0;
}
반응형

'ACM' 카테고리의 다른 글

[Accept] 10132 File Fragmentation  (0) 2009.06.02
[Accept] 10099 - The Tourist Guide  (0) 2009.06.02
[Time Limit] 10099 - The Tourist Guide  (0) 2009.06.02
[Accept] 10004 - Bicoloring problem  (0) 2009.06.02
[Accept] 100 - The 3n+1 problem  (0) 2009.06.02
posted by ssuk1010
:
ACM 2009. 6. 2. 20:51
반응형
I got time limite from Judge Server. T.T

#include <stdio.h>
 
#define MAX_CITY                101
#define DISCONNECTED        0
#define PASSED                        1
#define NOTPASSED                0
 
typedef struct TourInfo{
        int roadNum;                                                // road Number (input)
        int cityNum;                                                // city Number (input)
        int roadInfo[MAX_CITY][MAX_CITY];        // road info (max passenger info)
        int cityIsPassed[MAX_CITY];                 // passed or not passed
        int cityMinNum[MAX_CITY];                         // min Passenger Number 
        int startCity;                                                // start (input)
        int destCity;                                                // destination (input)
        int totalPassengerNum;                                // total passenger Number (input)
        int minPassengerNum;                                // result
}TourInfo;
 
void initTourInfo();
int findMinNumberOfTrips(int left);
 
TourInfo tour;
 
int main(void)
{
        int firstCity, secondCity, maxPassengerNum;
        int scenarioCount=0, result, i;
        while(1){
                
                scanf("%d %d", &tour.cityNum, &tour.roadNum);
                if(tour.cityNum==0  && tour.roadNum==0) break;
 
                result = 0;
                initTourInfo();
 
                for(i=0; i<tour.roadNum; i++){
                        scanf("%d %d %d", &firstCity, &secondCity, &maxPassengerNum);
                        tour.roadInfo[firstCity][secondCity] = maxPassengerNum;
                        tour.roadInfo[secondCity][firstCity] = maxPassengerNum;
                }
                scanf("%d %d %d", &tour.startCity, &tour.destCity, &tour.totalPassengerNum);
                if(tour.totalPassengerNum < 1) break;
 
                findMinNumberOfTrips(tour.startCity);
 
                scenarioCount++;
                result = tour.totalPassengerNum / (tour.minPassengerNum-1);   
                if(tour.totalPassengerNum % (tour.minPassengerNum-1))
                        result++;
 
                printf("Scenario #%d\n", scenarioCount);
                printf("Minimum Number of Trips = %d\n\n", result);
        } 
        return 0;
}
 
int findMinNumberOfTrips(int left)
{
        int i, right, minPass;
 
        tour.cityIsPassed[left]=PASSED; 
 
        // Last City
        if(left==tour.destCity){
                                
                if(!tour.minPassengerNum) {
                        tour.minPassengerNum = tour.cityMinNum[left];
                }
                else {
                        if(tour.minPassengerNum < tour.cityMinNum[left]) {
                                tour.minPassengerNum = tour.cityMinNum[left];
                        }
                }
                tour.cityMinNum[left]=NOTPASSED;
                tour.cityIsPassed[left]=NOTPASSED;
                return 1;
        }
 
        for(right=1; right<=tour.cityNum; right++)
        {
                if(tour.cityIsPassed[right]==PASSED) continue; // already passed city
 
                if(tour.roadInfo[left][right]!=0) // CONNECTED
                {
                        if(!tour.cityMinNum[left]){ // first path
                                tour.cityMinNum[right] = tour.roadInfo[left][right];
                        }
                        else{
                                if(tour.cityMinNum[left] > tour.roadInfo[left][right]){
                                        tour.cityMinNum[right] = tour.roadInfo[left][right];
                                }
                                else{
                                        tour.cityMinNum[right] = tour.cityMinNum[left];
                                }
                        }
 
                        if(tour.minPassengerNum >= tour.cityMinNum[right])
                                continue;
 
                        findMinNumberOfTrips(right);
                }
        }
        // init and return
        tour.cityMinNum[left]=NOTPASSED;
        tour.cityIsPassed[left]=NOTPASSED;
        return 1;
}
 
 
void initTourInfo()
{
        int i,j;
        for(i=0; i<MAX_CITY; i++) {
                for(j=0; j<MAX_CITY; j++) {
                        tour.roadInfo[i][j] = DISCONNECTED;
                }
                tour.cityIsPassed[i] = NOTPASSED;
                tour.cityMinNum[i] = NOTPASSED;
        }
        tour.minPassengerNum = 0;
}
반응형

'ACM' 카테고리의 다른 글

[Accept] 10099 - The Tourist Guide  (0) 2009.06.02
[Accept] 10099 - The Tourist Guide  (0) 2009.06.02
[Accept] 10004 - Bicoloring problem  (0) 2009.06.02
[Accept] 100 - The 3n+1 problem  (0) 2009.06.02
10006 - Carmichael Numbers  (0) 2009.06.02
posted by ssuk1010
:
ACM 2009. 6. 2. 20:49
반응형
I got accept from Judge Server

----------------------------------------------------------------------------------------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <stdio.h>
 
#define MAXV   200
#define NOCOLOR   0
#define BLACK   1
#define RED    2
#define CONNECTED  1
#define DISCONNECTED 0
 
typedef struct
{
 int edges[MAXV][MAXV];
 int color[MAXV];
 int nvertices;     
 int nedges;     
}Graph;
 
int  checkBicoloring(int init);
int  checkBicoloring(int init, int color);
void initEdge();
 
Graph graph;
 
int main(void)
{
 int i, first=0, second=0, checkBicolor=0;
 
 while(1){
  scanf("%d", &graph.nvertices);
  if(graph.nvertices == 0)
   break;
  
  if(graph.nvertices < 1 || graph.nvertices > MAXV)
   continue;
 
  scanf("%d", &graph.nedges);
 
  initEdge();
 
  for(i=0; i<graph.nedges; i++){
   scanf("%d %d", &first, &second);
   graph.edges[first][second] = CONNECTED;
   graph.edges[second][first] = CONNECTED;
  }
 
  if(checkBicoloring(0, BLACK) == 0){
   printf("BICOLORABLE.\n");
  } 
  else{
   printf("NOT BICOLORABLE.\n");
  }
 } 
 return 0;
}
 
void initEdge()
{
 int i, j;
 for(i=0; i<MAXV; i++){
  graph.color[i] = NOCOLOR;
  for(j=0; j<MAXV; j++){
   graph.edges[i][j] = DISCONNECTED;
  }
 }
}
 
int checkBicoloring(int init, int color)
{
 int i;
 if (graph.color[init] == NOCOLOR)
  graph.color[init] = color;
 
 for (i=0; i<graph.nvertices; i++){
  if (graph.edges[init][i] == CONNECTED){
   if(graph.color[init] == graph.color[i]){
    return 1;
   }
 
   if(graph.color[i] == NOCOLOR){ 
    if(graph.color[init] == BLACK)
     return checkBicoloring(i, RED);
    else
     return checkBicoloring(i, BLACK);
   } 
  }
 }
 return 0;
}


반응형

'ACM' 카테고리의 다른 글

[Accept] 10099 - The Tourist Guide  (0) 2009.06.02
[Time Limit] 10099 - The Tourist Guide  (0) 2009.06.02
[Accept] 100 - The 3n+1 problem  (0) 2009.06.02
10006 - Carmichael Numbers  (0) 2009.06.02
850 - Crypt Kicker II  (0) 2009.06.02
posted by ssuk1010
:
ACM 2009. 6. 2. 20:47
반응형


I got accept from Judge Server

----------------------------------------------------------------------------------------------

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#define MAX_NUM 1000000
int getCycleLength(unsigned int input);
 
typedef struct Number{
 int num1;
 int num2;
 unsigned int cycleLength;
}Number;
 
char *number;
 
int main(void)
{
 char line[100];
 int  numCount=0, tmp;
 int  i, cycleLength, check=0;
 Number  num;
 
 while(scanf("%d %d", &num.num1, &num.num2) == 2){
  
  if(num.num1>1000000 ||  num.num2>1000000 || num.num1<1 || num.num2<1){
   continue;
  }
 
  check = 0;
  if(num.num1 > num.num2){
   tmp       = num.num2;
   num.num2 = num.num1;
   num.num1 = tmp;
   check  = 1;
  }
 
  number = (char*)malloc(MAX_NUM);
  memset(number, '1', MAX_NUM);
 
  num.cycleLength = 0;
  for(i=num.num2; i>=num.num1; i--)
  {
   if(number[i-1]=='0')
    continue;
 
   cycleLength = getCycleLength(i);
   if(!cycleLength)
    return 0;
 
   if(cycleLength > num.cycleLength ){
    num.cycleLength = cycleLength;
   }
  }
  if(check){
   printf("%d %d %d\n", num.num2, num.num1, num.cycleLength);
  }
  else
  {
   printf("%d %d %d\n", num.num1, num.num2, num.cycleLength);
  }
  free(number);
 }
 return 0;
}
 
int getCycleLength(unsigned int input)
{
 unsigned int cycleLength=1;
 while(input != 1)
 {
  if(input-1<MAX_NUM && input>0){
   number[input-1] = '0';
  // printf("%d = %c\n", input, number[input-1]);
  }
  //printf("%d ", input);
  if(input%2 == 1){
   input = (input*3) +1;
   cycleLength++;
  }
  else {
   input = (input/2);
   cycleLength++;
  }
 }
 //printf("%d\n", input);
 return cycleLength;
}

반응형

'ACM' 카테고리의 다른 글

[Time Limit] 10099 - The Tourist Guide  (0) 2009.06.02
[Accept] 10004 - Bicoloring problem  (0) 2009.06.02
10006 - Carmichael Numbers  (0) 2009.06.02
850 - Crypt Kicker II  (0) 2009.06.02
10039 - Railroads  (0) 2009.06.02
posted by ssuk1010
:
ACM 2009. 6. 2. 20:38
반응형


  Carmichael Numbers 

An important topic nowadays in computer science is cryptography. Some people even think that cryptography is the only important field in computer science, and that life would not matter at all without cryptography. Alvaro is one of such persons, and is designing a set of cryptographic procedures for cooking paella. Some of the cryptographic algorithms he is implementing make use of big prime numbers. However, checking if a big number is prime is not so easy. An exhaustive approach can require the division of the number by all the prime numbers smaller or equal than its square root. For big numbers, the amount of time and storage needed for such operations would certainly ruin the paella.

However, some probabilistic tests exist that offer high confidence at low cost. One of them is the Fermat test.

Let a be a random number between 2 and n - 1 (being n the number whose primality we are testing). Then, n is probably prime if the following equation holds: 

\begin{displaymath}a^n \bmod n = a
\end{displaymath}

If a number passes the Fermat test several times then it is prime with a high probability.

Unfortunately, there are bad news. Some numbers that are not prime still pass the Fermat test with every number smaller than themselves. These numbers are called Carmichael numbers.

In this problem you are asked to write a program to test if a given number is a Carmichael number. Hopefully, the teams that fulfill the task will one day be able to taste a delicious portion of encrypted paella. As a side note, we need to mention that, according to Alvaro, the main advantage of encrypted paella over conventional paella is that nobody but you knows what you are eating.

Input 

The input will consist of a series of lines, each containing a small positive number n ( 2 < n < 65000). A number n = 0 will mark the end of the input, and must not be processed.

Output 

For each number in the input, you have to print if it is a Carmichael number or not, as shown in the sample output.

Sample Input 

1729
17
561
1109
431
0

Sample Output 

The number 1729 is a Carmichael number.
17 is normal.
The number 561 is a Carmichael number.
1109 is normal.
431 is normal.



Miguel Revilla 
2000-08-21

반응형

'ACM' 카테고리의 다른 글

[Accept] 10004 - Bicoloring problem  (0) 2009.06.02
[Accept] 100 - The 3n+1 problem  (0) 2009.06.02
850 - Crypt Kicker II  (0) 2009.06.02
10039 - Railroads  (0) 2009.06.02
10110 - Light, more light  (0) 2009.06.02
posted by ssuk1010
:
ACM 2009. 6. 2. 20:37
반응형

 

850 - Crypt Kicker II

Time limit: 3.000 seconds

  Crypt Kicker II 

A common but insecure method of encrypting text is to permute the letters of the alphabet. That is, in the text, each letter of the alphabet is consistently replaced by some other letter. So as to ensure that the encryption is reversible, no two letters are replaced by the same letter.

A common method of cryptanalysis is the known plaintext attack. In a known plaintext attack, the cryptanalist manages to have a known phrase or sentence encrypted by the enemy, and by observing the encrypted text then deduces the method of encoding.

Your task is to decrypt several encrypted lines of text, assuming that each line uses the same set of replacements, and that one of the lines of input is the encrypted form of the plaintext

the quick brown fox jumps over the lazy dog

Input 

The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs.


The input consists of several lines of input. Each line is encrypted as described above. The encrypted lines contain only lower case letters and spaces and do not exceed 80 characters in length. There are at most 100 input lines.

Output 

For each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line.


Decrypt each line and print it to standard output. If there is more than one possible decryption (several lines can be decoded to the key sentence), use the first line found for decoding. 

If decryption is impossible, output a single line:

No solution.

Sample Input 

1

vtz ud xnm xugm itr pyy jttk gmv xt otgm xt xnm puk ti xnm fprxq
xnm ceuob lrtzv ita hegfd tsmr xnm ypwq ktj
frtjrpgguvj otvxmdxd prm iev prmvx xnmq

Sample Output 

now is the time for all good men to come to the aid of the party
the quick brown fox jumps over the lazy dog
programming contests are fun arent they
반응형

'ACM' 카테고리의 다른 글

[Accept] 100 - The 3n+1 problem  (0) 2009.06.02
10006 - Carmichael Numbers  (0) 2009.06.02
10039 - Railroads  (0) 2009.06.02
10110 - Light, more light  (0) 2009.06.02
10132 - File Fragmentation  (0) 2009.06.02
posted by ssuk1010
:
ACM 2009. 6. 2. 20:36
반응형


  Problem A: Railroads 

Background 

It's Friday evening and Jill hates two things which are common to all trains:
1.
They are always late.
2.
The schedule is always wrong.

Nevertheless, tomorrow in the early morning hours Jill will have to travel from Hamburg to Darmstadt in order to get to the regional programming contest. Since she is afraid of arriving too late and being excluded from the contest she is looking for the train which gets her to Darmstadt as early as possible. However, she dislikes to get to the station too early, so if there are several schedules with the same arrival time then she will choose the one with the latest departure time.

Problem 

Jill asks you to help her with her problem. You are given a set of railroad schedules from which you must compute the train with the earliest arrival time and the fastest connection from one location to another. One good thing: Jill is very experienced in changing trains. She can do this instantaneously, i.e., in zero time!!!

Input 

The very first line of the input gives the number of scenarios. Each scenario consists of three parts.

Part one lists the names of all cities connected by the railroads. It starts with a number $1<C \le 100$, followed by C lines containing city names. These names consist of letters.

Part two describes all the trains running during a day. It starts with a number $T \le 1000$ followed by T train descriptions. Each of them consists of one line with a number $t_i \le 100$ and ti more lines with a time and a city name, meaning that passengers can get on or off the train at that time at that city.

Part three consists of three lines: Line one contains the earliest journey's starting time, line two the name of the city where she starts, and line three the destination city. The two cities are always different.

Output 

For each scenario print a line containing ``Scenario i'', where i is the number of the scenario starting at 1.

If a connection exists then print the two lines containing zero padded timestamps and locations as shown in the sample. Use blanks to achieve the indentation. If no connection exists on the same day (i.e., arrival before midnight) then print a line containing ``No connection''.

After each scenario print a blank line.

Sample Input 

2
3
Hamburg
Frankfurt
Darmstadt
3
2
0949 Hamburg
1006 Frankfurt
2
1325 Hamburg
1550 Darmstadt
2
1205 Frankfurt
1411 Darmstadt
0800
Hamburg
Darmstadt
2
Paris
Tokyo
1
2
0100 Paris
2300 Tokyo
0800
Paris
Tokyo

Sample Output 

Scenario 1
Departure 0949 Hamburg
Arrival   1411 Darmstadt

Scenario 2
No connection



Miguel Revilla 
2000-11-19
반응형

'ACM' 카테고리의 다른 글

10006 - Carmichael Numbers  (0) 2009.06.02
850 - Crypt Kicker II  (0) 2009.06.02
10110 - Light, more light  (0) 2009.06.02
10132 - File Fragmentation  (0) 2009.06.02
10099 - The Tourist Guide  (0) 2009.06.02
posted by ssuk1010
:
ACM 2009. 6. 2. 20:34
반응형

 
Light, more light

The Problem

There is man named "mabu" for switching on-off light in our University. He switches on-off the lights in a corridor. Every bulb has its own toggle switch. That is, if it is pressed then the bulb turns on. Another press will turn it off. To save power consumption (or may be he is mad or something else) he does a peculiar thing. If in a corridor there is `n' bulbs, he walks along the corridor back and forth `n' times and in i'th walk he toggles only the switches whose serial is divisable by i. He does not press any switch when coming back to his initial position. A i'th walk is defined as going down the corridor (while doing the peculiar thing) and coming back again.

Now you have to determine what is the final condition of the last bulb. Is it on or off? 
 

The Input

The input will be an integer indicating the n'th bulb in a corridor. Which is less then or equals 2^32-1. A zero indicates the end of input. You should not process this input.

The Output

Output "yes" if the light is on otherwise "no" , in a single line.

Sample Input

3
6241
8191
0

Sample Output

no
yes
no

Sadi Khan 
Suman Mahbub 
01-04-2001
반응형

'ACM' 카테고리의 다른 글

850 - Crypt Kicker II  (0) 2009.06.02
10039 - Railroads  (0) 2009.06.02
10132 - File Fragmentation  (0) 2009.06.02
10099 - The Tourist Guide  (0) 2009.06.02
10004 - Bicoloring  (0) 2009.06.02
posted by ssuk1010
:
ACM 2009. 6. 2. 20:33
반응형

 

Question 2: File Fragmentation

The Problem

Your friend, a biochemistry major, tripped while carrying a tray of computer files through the lab. All of the files fell to the ground and broke. Your friend picked up all the file fragments and called you to ask for help putting them back together again.

Fortunately, all of the files on the tray were identical, all of them broke into exactly two fragments, and all of the file fragments were found. Unfortunately, the files didn't all break in the same place, and the fragments were completely mixed up by their fall to the floor.

You've translated the original binary fragments into strings of ASCII 1's and 0's, and you're planning to write a program to determine the bit pattern the files contained.

Input

The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs.

Input will consist of a sequence of ``file fragments'', one per line, terminated by the end-of-file marker. Each fragment consists of a string of ASCII 1's and 0's.

Output

For each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line.

Output is a single line of ASCII 1's and 0's giving the bit pattern of the original files. If there are 2N fragments in the input, it should be possible to concatenate these fragments together in pairs to make N copies of the output string. If there is no unique solution, any of the possible solutions may be output.

Your friend is certain that there were no more than 144 files on the tray, and that the files were all less than 256 bytes in size.

Sample Input

1

011
0111
01110
111
0111
10111

Sample Output

01110111
반응형

'ACM' 카테고리의 다른 글

10039 - Railroads  (0) 2009.06.02
10110 - Light, more light  (0) 2009.06.02
10099 - The Tourist Guide  (0) 2009.06.02
10004 - Bicoloring  (0) 2009.06.02
100 - The 3n + 1 problem  (0) 2009.06.02
posted by ssuk1010
: