'ACM'에 해당되는 글 20건

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

10099 - The Tourist Guide

Time limit: 3.000 seconds

Problem D

The Tourist Guide

Input: standard input

Output: standard output

 

Mr. G. works as a tourist guide. His current assignment is to take some tourists from one city to another. Some two-way roads connect the cities. For each pair of neighboring cities there is a bus service that runs only between those two cities and uses the road that directly connects them. Each bus service has a limit on the maximum number of passengers it can carry. Mr. G. has a map showing the cities and the roads connecting them. He also has the information regarding each bus service. He understands that it may not always be possible for him to take all the tourists to the destination city in a single trip. For example, consider the following road map of 7 cities. The edges connecting the cities represent the roads and the number written on each edge indicates the passenger limit of the bus service that runs on that road.

 

                           

Now, if he wants to take 99 tourists from city 1 to city 7, he will require at least 5 trips, since he has to ride the bus with each group, and the route he should take is : 1 - 2 - 4 - 7.

But, Mr. G. finds it difficult to find the best route all by himself so that he may be able to take all the tourists to the destination city in minimum number of trips. So, he seeks your help.

 

Input

The input will contain one or more test cases. The first line of each test case will contain two integers: N (N<= 100) and Rrepresenting respectively the number of cities and the number of road segments. Then R lines will follow each containing three integers: C1, C2 and P. C1 and C2 are the city numbers and P (P> 1) is the limit on the maximum number of passengers to be carried by the bus service between the two cities. City numbers are positive integers ranging from 1 to N. The (R + 1)-th line will contain three integers: S, D and T representing respectively the starting city, the destination city and the number of tourists to be guided.

The input will end with two zeroes for N and R.

 

Output

For each test case in the input first output the scenario number. Then output the minimum number of trips required for this case on a separate line. Print a blank line after the output of each test case.

 

Sample Input

7 10
1 2 30
1 3 15
1 4 10
2 4 25
2 5 60
3 4 40
3 6 20
4 7 35
5 7 20
6 7 30
1 7 99
0 0

Sample Output

Scenario #1
Minimum Number of Trips = 5
반응형

'ACM' 카테고리의 다른 글

10039 - Railroads  (0) 2009.06.02
10110 - Light, more light  (0) 2009.06.02
10132 - File Fragmentation  (0) 2009.06.02
10004 - Bicoloring  (0) 2009.06.02
100 - The 3n + 1 problem  (0) 2009.06.02
posted by ssuk1010
:
ACM 2009. 6. 2. 20:28
반응형
 

Bicoloring 

In 1976 the ``Four Color Map Theorem" was proven with the assistance of a computer. This theorem states that every map can be colored using only four colors, in such a way that no region is colored using the same color as a neighbor region.

Here you are asked to solve a simpler similar problem. You have to decide whether a given arbitrary connected graph can be bicolored. That is, if one can assign colors (from a palette of two) to the nodes in such a way that no two adjacent nodes have the same color. To simplify the problem you can assume:

  • no node will have an edge to itself.
  • the graph is nondirected. That is, if a node a is said to be connected to a node b, then you must assume that b is connected to a.
  • the graph will be strongly connected. That is, there will be at least one path from any node to any other node.

Input 

The input consists of several test cases. Each test case starts with a line containing the number n ( 1 < n < 200) of different nodes. The second line contains the number of edges l. After this, l lines will follow, each containing two numbers that specify an edge between the two nodes that they represent. A node in the graph will be labeled using a number a ( $0 \le a < n$).

An input with n = 0 will mark the end of the input and is not to be processed.

Output 

You have to decide whether the input graph can be bicolored or not, and print it as shown below.

Sample Input 

3
3
0 1
1 2
2 0
9
8
0 1
0 2
0 3
0 4
0 5
0 6
0 7
0 8
0

Sample Output 

NOT BICOLORABLE.
BICOLORABLE.
반응형

'ACM' 카테고리의 다른 글

10039 - Railroads  (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
100 - The 3n + 1 problem  (0) 2009.06.02
posted by ssuk1010
:
ACM 2009. 6. 2. 20:25
반응형

100 - The 3n + 1 problem

Time limit: 3.000 seconds
 
 The 3n + 1 problem 

Background

Problems in Computer Science are often classified as belonging to a certain class of problems (e.g., NP, Unsolvable, Recursive). In this problem you will be analyzing a property of an algorithm whose classification is not known for all possible inputs.

The Problem

Consider the following algorithm:

 		1. 		 input n

2. print n

3. if n = 1 then STOP

4. if n is odd then n = 3n+1

5. else n = n/2

6. GOTO 2

Given the input 22, the following sequence of numbers will be printed 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1

It is conjectured that the algorithm above will terminate (when a 1 is printed) for any integral input value. Despite the simplicity of the algorithm, it is unknown whether this conjecture is true. It has been verified, however, for all integers nsuch that 0 < n < 1,000,000 (and, in fact, for many more numbers than this.)

Given an input n, it is possible to determine the number of numbers printed (including the 1). For a given n this is called the cycle-length of n. In the example above, the cycle length of 22 is 16.

For any two numbers i and j you are to determine the maximum cycle length over all numbers between i and j.

The Input

The input will consist of a series of pairs of integers i and j, one pair of integers per line. All integers will be less than 1,000,000 and greater than 0.

You should process all pairs of integers and for each pair determine the maximum cycle length over all integers between and including i and j.

You can assume that no operation overflows a 32-bit integer.

The Output

For each pair of input integers i and j you should output i, j, and the maximum cycle length for integers between and including i and j. These three numbers should be separated by at least one space with all three numbers on one line and with one line of output for each line of input. The integers i and j must appear in the output in the same order in which they appeared in the input and should be followed by the maximum cycle length (on the same line).

Sample Input

1 10100 200201 210900 1000

Sample Output

1 10 20100 200 125201 210 89900 1000 174

반응형

'ACM' 카테고리의 다른 글

10039 - Railroads  (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
10004 - Bicoloring  (0) 2009.06.02
posted by ssuk1010
: