├── .gitignore ├── 100-199 ├── 100.cpp ├── 101.cpp ├── 102.cpp ├── 103.cpp ├── 104.cpp ├── 105.cpp ├── 106.cpp ├── 107.cpp ├── 108.cpp ├── 109.cpp ├── 111.cpp ├── 111.java ├── 112.cpp ├── 113.cpp ├── 114.cpp ├── 115.cpp ├── 116.cpp ├── 117.cpp ├── 118.cpp ├── 119.cpp ├── 120.cpp ├── 123.cpp ├── 124.cpp ├── 125.cpp ├── 126.cpp ├── 127.cpp ├── 130.cpp ├── 131.cpp ├── 133.cpp ├── 134.cpp ├── 135.cpp ├── 139.cpp ├── 142.cpp ├── 143.cpp ├── 144.cpp ├── 146.cpp ├── 149.cpp ├── 152.cpp ├── 154.cpp ├── 163.cpp ├── 168.cpp ├── 169.cpp ├── 170.cpp ├── 172.cpp ├── 175.cpp ├── 179.cpp ├── 180.cpp ├── 181.cpp ├── 184.cpp ├── 186.cpp ├── 193.java ├── 196.cpp ├── 199.cpp └── README.md ├── 200-299 ├── 222.cpp ├── 223.cpp ├── 224.cpp ├── 226.cpp ├── 231.cpp ├── 259.cpp ├── 276.cpp ├── 296.cpp └── 297.cpp ├── 300-399 ├── 302.cpp ├── 316.cpp └── 358.cpp ├── 400-499 ├── 403.cpp └── 404.cpp ├── LICENSE ├── README.md └── RankAC.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Compiled Dynamic libraries 12 | *.so 13 | *.dylib 14 | *.dll 15 | 16 | # Fortran module files 17 | *.mod 18 | 19 | # Compiled Static libraries 20 | *.lai 21 | *.la 22 | *.a 23 | *.lib 24 | 25 | # Executables 26 | *.exe 27 | *.out 28 | *.app 29 | 30 | test 31 | *~ 32 | .DS_Store 33 | -------------------------------------------------------------------------------- /100-199/100.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Read integers A and B from input file and write their sum in output file. 3 | 4 | Input 5 | 6 | Input file contains A and B (0 22 | using namespace std; 23 | 24 | int main() { 25 | int a,b; 26 | cin >> a >> b; 27 | cout << a+b; 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /100-199/101.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************** 2 | 101. Domino 3 | time limit per test: 0.25 sec. 4 | memory limit per test: 4096 KB 5 | Dominoes – game played with small, rectangular blocks of wood or other material, each identified by a number of dots, or pips, on its face. The blocks usually are called bones, dominoes, or pieces and sometimes men, stones, or even cards. 6 | The face of each piece is divided, by a line or ridge, into two squares, each of which is marked as would be a pair of dice... 7 | The principle in nearly all modern dominoes games is to match one end of a piece to another that is identically or reciprocally numbered. 8 | ENCYCLOPÆDIA BRITANNICA 9 | Given a set of domino pieces where each side is marked with two digits from 0 to 6. Your task is to arrange pieces in a line such way, that they touch through equal marked sides. It is possible to rotate pieces changing left and right side. 10 | Input 11 | The first line of the input contains a single integer N (1 ≤ N ≤ 100) representing the total number of pieces in the domino set. The following N lines describe pieces. Each piece is represented on a separate line in a form of two digits from 0 to 6 separated by a space. 12 | Output 13 | Write “No solution” if it is impossible to arrange them described way. If it is possible, write any of way. Pieces must be written in left-to-right order. Every of N lines must contains number of current domino piece and sign “+” or “-“ (first means that you not rotate that piece, and second if you rotate it). 14 | Sample Input 15 | 5 16 | 1 2 17 | 2 4 18 | 2 4 19 | 6 4 20 | 2 1 21 | Sample Output 22 | 2 - 23 | 5 + 24 | 1 + 25 | 3 + 26 | 4 - 27 | *******************************************************************************************/ 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | using namespace std; 35 | 36 | int N = 0; 37 | int occ[7] = {0}; 38 | int START = 0; 39 | 40 | struct Edge{ 41 | int v1,v2; 42 | bool visited; 43 | Edge(){}; 44 | Edge(int _v1, int _v2, bool _vis){ 45 | v1 = _v1;v2 = _v2;visited = _vis; 46 | } 47 | }; 48 | struct Edge Edges[110]; 49 | map< int , vector >maps; 50 | 51 | /* 52 | * 返回一个节点的所有边 53 | */ 54 | vector getEdge(int n){ 55 | vector set; 56 | for(int i = 0;i < N;i++){ 57 | if(n == Edges[i].v1 || n == Edges[i].v2){ 58 | set.push_back(i); 59 | } 60 | } 61 | return set; 62 | } 63 | 64 | void res(int start,vector& s){ 65 | for(int i = s.size()-1;i >= 0;i--){ 66 | int front = Edges[s[i]].v1; 67 | int back = Edges[s[i]].v2; 68 | if(start == front){ 69 | cout << s[i]+1 << " +" << endl; 70 | start = back; 71 | } else { 72 | cout << s[i]+1 << " -" << endl; 73 | start = front; 74 | } 75 | } 76 | } 77 | 78 | void through(int start, vector& s){ 79 | vectore = maps[start]; 80 | for(int i = 0;i < e.size();i++){ 81 | if(Edges[e[i]].visited) 82 | continue; 83 | else{ 84 | Edges[e[i]].visited = true; 85 | if(start == Edges[e[i]].v1){ 86 | through(Edges[e[i]].v2, s); 87 | s.push_back(e[i]); 88 | } else { 89 | through(Edges[e[i]].v1, s); 90 | s.push_back(e[i]); 91 | } 92 | } 93 | } 94 | return; 95 | } 96 | 97 | 98 | int main() 99 | { 100 | int front,back; 101 | cin >> N; 102 | 103 | int index = 0; 104 | while(cin >> front && cin >> back) 105 | { 106 | Edges[index] = Edge(front,back,false); 107 | index++; 108 | occ[front]++; 109 | occ[back]++; 110 | } 111 | 112 | int odd_pot = 0, start = Edges[0].v1; 113 | for(int i = 0;i < 7;i++){ 114 | if(occ[i] % 2 == 1){ 115 | odd_pot++; 116 | start = i; 117 | } 118 | maps[i] = getEdge(i); 119 | } 120 | START = start; 121 | if(odd_pot != 0 && odd_pot != 2){ 122 | cout << "No solution"; 123 | return 0; 124 | } 125 | 126 | vectorresults; 127 | through(start,results); 128 | //如果不是联通图 129 | if(results.size() < N)cout << "No solution"; 130 | else res(START,results); 131 | 132 | return 0; 133 | } 134 | -------------------------------------------------------------------------------- /100-199/102.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | For given integer N (1<=N<=104) find amount of positive numbers not greater than N that coprime with N. Let us call two positive integers (say, A and B, for example) coprime if (and only if) their greatest common divisor is 1. (i.e. A and B are coprime iff gcd(A,B) = 1). 4 | 5 | Input 6 | 7 | Input file contains integer N. 8 | 9 | Output 10 | 11 | Write answer in output file. 12 | 13 | Sample Input 14 | 15 | 9 16 | Sample Output 17 | 18 | 6 19 | 20 | 21 | */ 22 | 23 | #include 24 | using namespace std; 25 | 26 | 27 | int gcd ( int a, int b ) 28 | { 29 | int c; 30 | while ( a != 0 ) { 31 | c = a; a = b%a; b = c; 32 | } 33 | return b; 34 | } 35 | 36 | int main() 37 | { 38 | int N; 39 | cin >> N; 40 | int res = 0; 41 | for(int i = 1;i <= N;i++) 42 | if(gcd(i, N) == 1) 43 | res++; 44 | cout << res; 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /100-199/103.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 103. Traffic Lights 3 | 4 | Time limit per test: 0.25 second(s) 5 | Memory limit: 4096 kilobytes 6 | input: standard 7 | output: standard 8 | 9 | 10 | 11 | In the city of Dingilville the traffic is arranged in an unusual way. There are junctions and roads connecting the junctions. There is at most one road between any two different junctions. There is no road connecting a junction to itself. Travel time for a road is the same for both directions. At every junction there is a single traffic light that is either blue or purple at any moment. The color of each light alternates periodically: blue for certain duration and then purple for another duration. Traffic is permitted to travel down the road between any two junctions, if and only if the lights at both junctions are the same color at the moment of departing from one junction for the other. If a vehicle arrives at a junction just at the moment the lights switch it must consider the new colors of lights. Vehicles are allowed to wait at the junctions. You are given the city map which shows: 12 | the travel times for all roads (integers) 13 | the durations of the two colors at each junction (integers) 14 | and the initial color of the light and the remaining time (integer) for this color to change at each junction. 15 | 16 | Your task is to find a path which takes the minimum time from a given source junction to a given destination junction for a vehicle when the traffic starts. In case more than one such path exists you are required to report only one of them. 17 | 18 | Input 19 | The first line contains two numbers: The id-number of the source junction and the id-number of the destination junction. The second line contains two numbers: N, M. The following N lines contain information on N junctions. The (i+2)'th line of the input file holds information about the junction i : Ci, riC, tiB, tiP where Ci is either B for blue or P for purple, indicating the initial color of the light at the junction i. Finally, the next M lines contain information on M roads. Each line is of the form: i, j, lij where i and j are the id-numbers of the junctions which are connected by this road. 2 ≤ N ≤ 300 where N is the number of junctions. The junctions are identified by integers 1 through N. These numbers are called id-numbers. 1 ≤ M ≤ 14000 where M is the number of roads. 1 ≤ lij ≤ 100 where lij is the time required to move from junction i to j using the road that connects i and j. 1 ≤ tiC ≤ 100 where tiC is the duration of the color c for the light at the junction i. The index c is either 'B' for blue or 'P' for purple. 1 ≤ riC ≤ tiC where riC is the remaining time for the initial color c at junction i. 20 | 21 | Output 22 | If a path exists: 23 | The first line will contain the time taken by a minimum-time path from the source junction to the destination junction. 24 | Second line will contain the list of junctions that construct the minimum-time path you have found. You have to write the junctions to the output file in the order of travelling. Therefore the first integer in this line must be the id-number of the source junction and the last one the id-number of the destination junction. 25 | 26 | If a path does not exist: 27 | A single line containing only the integer 0. 28 | ************************************************************************/ 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | using namespace std; 36 | 37 | int n,m,st,ed; 38 | int r[310],c[310],ans[310],dist[310],last[310]; 39 | int t[310][2]; 40 | int map[310][310]; 41 | bool v[310]; 42 | int q[30010]; 43 | 44 | inline int cmin(const int &x,const int &y) {return x0) 110 | { 111 | int temp=calctime(now,i,dist[now],0); 112 | if (temp>=INT_MAX) continue; 113 | if (temp+map[now][i]=INT_MAX) {printf("0");return;} 124 | printf("%d\n",dist[ed]); 125 | int now=ed,len=0; 126 | while (now!=0) {len++;ans[len]=now;now=last[now];} 127 | for (int i=len;i>=2;i--) printf("%d ",ans[i]); 128 | printf("%d\n",ans[1]); 129 | return; 130 | } 131 | 132 | int main() 133 | { 134 | init(); 135 | spfa(); 136 | return 0; 137 | } -------------------------------------------------------------------------------- /100-199/104.cpp: -------------------------------------------------------------------------------- 1 | /********************************************************************************************************** 2 | 104. Little shop of flowers 3 | 4 | 5 | time limit per test: 0.25 sec. 6 | memory limit per test: 4096 KB 7 | 8 | 9 | PROBLEM 10 | 11 | You want to arrange the window of your flower shop in a most pleasant way. You have F bunches of flowers, each being of a different kind, and at least as many vases ordered in a row. The vases are glued onto the shelf and are numbered consecutively 1 through V, where V is the number of vases, from left to right so that the vase 1 is the leftmost, and the vase V is the rightmost vase. The bunches are moveable and are uniquely identified by integers between 1 and F. These id-numbers have a significance: They determine the required order of appearance of the flower bunches in the row of vases so that the bunch i must be in a vase to the left of the vase containing bunch j whenever i < j. Suppose, for example, you have bunch of azaleas (id-number=1), a bunch of begonias (id-number=2) and a bunch of carnations (id-number=3). Now, all the bunches must be put into the vases keeping their id-numbers in order. The bunch of azaleas must be in a vase to the left of begonias, and the bunch of begonias must be in a vase to the left of carnations. If there are more vases than bunches of flowers then the excess will be left empty. A vase can hold only one bunch of flowers. 12 | 13 | Each vase has a distinct characteristic (just like flowers do). Hence, putting a bunch of flowers in a vase results in a certain aesthetic value, expressed by an integer. The aesthetic values are presented in a table as shown below. Leaving a vase empty has an aesthetic value of 0. 14 | 15 | 16 | 17 | According to the table, azaleas, for example, would look great in vase 2, but they would look awful in vase 4. 18 | 19 | To achieve the most pleasant effect you have to maximize the sum of aesthetic values for the arrangement while keeping the required ordering of the flowers. If more than one arrangement has the maximal sum value, any one of them will be acceptable. You have to produce exactly one arrangement. 20 | 21 | ASSUMPTIONS 22 | 23 | 1 ≤ F ≤ 100 where F is the number of the bunches of flowers. The bunches are numbered 1 through F. 24 | F ≤ V ≤ 100 where V is the number of vases. 25 | -50 £ Aij £ 50 where Aij is the aesthetic value obtained by putting the flower bunch i into the vase j. 26 | 27 | Input 28 | The first line contains two numbers: F, V. 29 | The following F lines: Each of these lines contains V integers, so that Aij is given as the j’th number on the (i+1)’st line of the input file. 30 | 31 | Output 32 | The first line will contain the sum of aesthetic values for your arrangement. 33 | The second line must present the arrangement as a list of F numbers, so that the k’th number on this line identifies the vase in which the bunch k is put. 34 | ******************************************************************************/ 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | using namespace std; 41 | 42 | int main() 43 | { 44 | int N,M; 45 | cin >> N >> M; 46 | vector >table(N+1, vector(M+1, 0)); 47 | for(int i = 1;i <= N;i++) 48 | for(int j = 1;j <= M;j++) 49 | cin >> table[i][j]; 50 | vector >p = table; 51 | 52 | 53 | for(int i = 1;i <= N;i++) 54 | { 55 | for(int j = i;j <= M;j++) 56 | { 57 | if(i == j) table[i][j] += table[i-1][j-1]; 58 | else table[i][j] = max(table[i-1][j-1]+table[i][j], table[i][j-1]); 59 | } 60 | } 61 | /* 62 | for(int i = 1;i <= N;i++) 63 | { 64 | for(int j = 1;j <= M;j++) 65 | { 66 | cout << table[i][j] << " "; 67 | } 68 | cout << endl; 69 | }*/ 70 | 71 | cout << table[N][M] << endl; 72 | 73 | int i(N),j(M); 74 | stack _s; 75 | while(i > 0) 76 | { 77 | if(table[i][j] == table[i-1][j-1] + p[i][j]) 78 | { 79 | _s.push(j); 80 | i--; 81 | j--; 82 | } else { 83 | j--; 84 | } 85 | } 86 | 87 | while(!_s.empty()) 88 | { 89 | cout << _s.top() << " "; 90 | _s.pop(); 91 | } 92 | 93 | return 0; 94 | } 95 | -------------------------------------------------------------------------------- /100-199/105.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | There is sequence 1, 12, 123, 1234, ..., 12345678910, ... . Given first N elements of that sequence. You must determine amount of numbers in it that are divisible by 3. 3 | 4 | Input 5 | 6 | Input contains N (1<=N<=231 - 1). 7 | 8 | Output 9 | 10 | Write answer to the output. 11 | 12 | Sample Input 13 | 14 | 4 15 | Sample Output 16 | 17 | 2 18 | */ 19 | 20 | #include 21 | using namespace std; 22 | 23 | int main() 24 | { 25 | int N; 26 | cin >> N; 27 | 28 | int ans = 0; 29 | if (N % 3 == 2) 30 | ans++; 31 | ans += 2 * (N / 3); 32 | cout << ans; 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /100-199/106.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 106. The equation 3 | 4 | 5 | time limit per test: 0.25 sec. 6 | memory limit per test: 4096 KB 7 | 8 | There is an equation ax + by + c = 0. Given a,b,c,x1,x2,y1,y2 you must determine, how many integer roots of this equation are satisfy to the following conditions : x1<=x<=x2, y1<=y<=y2. Integer root of this equation is a pair of integer numbers (x,y). 9 | 10 | Input 11 | 12 | Input contains integer numbers a,b,c,x1,x2,y1,y2 delimited by spaces and line breaks. All numbers are not greater than 108 by absolute value. 13 | 14 | Output 15 | 16 | Write answer to the output. 17 | 18 | Sample Input 19 | 20 | 1 1 -3 21 | 0 4 22 | 0 4 23 | Sample Output 24 | 25 | 4 26 | ************************************************************************/ 27 | #include 28 | #include 29 | using namespace std; 30 | 31 | long long x0,yy0; 32 | 33 | long long gcd(long long a,long long b) 34 | { 35 | if (b==0) return a; 36 | return gcd(b,a % b); 37 | } 38 | 39 | void exgcd(long long a,long long b) 40 | { 41 | if (b==0){x0=1;yy0=0;return;} 42 | exgcd(b,a%b); 43 | long long t=x0;x0=yy0;yy0=t-a/b*yy0; 44 | return; 45 | } 46 | 47 | int main() 48 | { 49 | long long a,b,c,x1,x2,y1,y2; 50 | cin >> a >> b >> c >> x1 >> x2 >> y1 >> y2; 51 | c=-c; 52 | if (c<0) {a=-a;b=-b;c=-c;} 53 | if (a<0) {a=-a;long long t=x1;x1=-x2;x2=-t;} 54 | if (b<0) {b=-b;long long t=y1;y1=-y2;y2=-t;} 55 | if (a==0 && b==0) 56 | { 57 | if (c==0) 58 | { 59 | cout << (x2-x1+1)*(y2-y1+1); 60 | return 0; 61 | } 62 | cout << 0; 63 | return 0; 64 | } 65 | else if (a==0) 66 | { 67 | if (c %b ==0) 68 | if (c/b<=y2 && c/b>=y1) {cout << x2-x1+1;return 0;} 69 | cout << 0;return 0; 70 | } 71 | else if (b==0) 72 | { 73 | if (c%a==0) 74 | if (c/a<=x2 && c/a>=x1) {cout << y2-y1+1;return 0;} 75 | cout << 0;return 0; 76 | } 77 | 78 | long long d=gcd(a,b); 79 | if (c%d!=0){cout << 0;return 0;} 80 | 81 | a=a/d;b=b/d;c=c/d; 82 | exgcd(a,b); 83 | x0=x0*c;yy0=yy0*c; 84 | 85 | double tx2=x2,tx1=x1,tx0=x0,ta=a,tb=b,tc=c,ty1=y1,ty2=y2,ty0=yy0; 86 | long long down1=floor(((tx2-tx0)/tb)),down2=floor(((ty0-ty1)/ta)); 87 | long long r=min(down1,down2); 88 | long long up1=ceil(((tx1-tx0)/tb)),up2=ceil(((ty0-ty2)/ta)); 89 | long long l=max(up1,up2); 90 | if (r 27 | using namespace std; 28 | 29 | int main() 30 | { 31 | //for(long long int i = 1;i <= 999999999;i++) 32 | // if(i*i % 1000000000 == 987654321) 33 | // cout << i << endl; 34 | 35 | int N; 36 | cin >> N; 37 | 38 | if(N <= 8) cout << 0; 39 | else if(N == 9) cout << 8; 40 | else { 41 | cout << 72; 42 | string str(N-10,'0'); 43 | cout << str; 44 | } 45 | 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /100-199/108.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************************************8 2 | 108. Self-numbers 2 3 | 4 | 5 | time limit per test: 0.5 sec. 6 | memory limit per test: 4096 KB 7 | 8 | In 1949 the Indian mathematician D.R. Kaprekar discovered a class of numbers called self-numbers. For any positive integer n, define d(n) to be n plus the sum of the digits of n. (The d stands for digitadition, a term coined by Kaprekar.) For example, d(75) = 75 + 7 + 5 = 87. Given any positive integer n as a starting point, you can construct the infinite increasing sequence of integers n, d(n), d(d(n)), d(d(d(n))), .... For example, if you start with 33, the next number is 33 + 3 + 3 = 39, the next is 39 + 3 + 9 = 51, the next is 51 + 5 + 1 = 57, and so you generate the sequence 33, 39, 51, 57, 69, 84, 96, 111, 114, 120, 123, 129, 141, ... The number n is called a generator of d(n). In the sequence above, 33 is a generator of 39, 39 is a generator of 51, 51 is a generator of 57, and so on. Some numbers have more than one generator: for example, 101 has two generators, 91 and 100. A number with no generators is a self-number. Let the a[i] will be i-th self-number. There are thirteen self-numbers a[1]..a[13] less than 100: 1, 3, 5, 7, 9, 20, 31, 42, 53, 64, 75, 86, and 97. (the first self-number is a[1]=1, the second is a[2] = 3, :, the thirteen is a[13]=97); 9 | 10 | Input 11 | 12 | Input contains integer numbers N, K, s1...sk. (1<=N<=107, 1<=K<=5000) delimited by spaces and line breaks. 13 | 14 | Output 15 | 16 | At first line you must output one number - the quantity of self-numbers in interval [1..N]. Second line must contain K numbers - a[s1]..a[sk], delimited by spaces. It`s a gaurantee, that all self-numbers a[s1]..a[sk] are in interval [1..N]. (for example if N = 100, sk can be 1..13 and cannot be 14, because 14-th self-number a[14] = 108, 108 > 100) 17 | 18 | Sample Input 19 | 20 | 100 10 21 | 1 2 3 4 5 6 7 11 12 13 22 | Sample Output 23 | 24 | 13 25 | 1 3 5 7 9 20 31 75 86 97 26 | ********************************************************************************************/ 27 | 28 | #include 29 | using namespace std; 30 | 31 | int apply(int d) 32 | { 33 | int res(d); 34 | while(d > 0) 35 | { 36 | int tmp = d % 10; 37 | d = d/10; 38 | res += tmp; 39 | } 40 | return res; 41 | } 42 | 43 | 44 | 45 | int main() 46 | { 47 | bool flag[64] = {false}; 48 | int N,K; cin >> N >> K; 49 | int res[1000000]; 50 | int total(0); 51 | 52 | for(int i = 1;i <= N;i++) 53 | { 54 | if(flag[i%64] == false) 55 | { 56 | res[total] = i; 57 | total++; 58 | } 59 | flag[i%64] = false; 60 | 61 | int tmp = apply(i); 62 | flag[tmp%64] = true; 63 | } 64 | 65 | cout << total << endl; 66 | while(K--) 67 | { 68 | int pos; 69 | cin >> pos; 70 | cout << res[pos-1] << " "; 71 | } 72 | 73 | return 0; 74 | } 75 | 76 | -------------------------------------------------------------------------------- /100-199/109.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 109. git 3 | 4 | 5 | time limit per test: 0.25 sec. 6 | memory limit per test: 4096 KB 7 | 8 | The well-known magician David Copperfield loves lo show the following trick: a square with N rows and N columns of different pictures appears on a TV screen, Let us number all the pictures in the following order: 9 | 10 | 1 2 ... N 11 | ... ... ... ... 12 | N*(N-1)+1 N*(N-1)+2 ... N*N 13 | 14 | Each member of the audience is asked to put a finger on the upper left picture (i.e., picture number one) and The Magic begins: the magician tells the audience to move the finger K1 times through the pictures (each move is a shift of the finger to the adjacent picture up, down, left or right provided that there is a picture to move to), then with a slight movement of his hand he removes some of the pictures with an exclamation "You are not there!", and ... it is true - your finger is not pointing to any of the pictures removed. Then again, he tells the audience to make K2 moves, and so on. At the end he removes all the pictures but one and smiling triumphantly declares, "I've caught you" (applause). 15 | 16 | Just now, David is trying to repeat this trick. Unfortunately, he had-a hard day before, and you know how hard to conjure with a headache. You have to write a program that will help David to make his trick. 17 | 18 | Input 19 | 20 | The input file contains a single integer number N (1Kj when i<>j). Xi,1 Xi,2 ... Xi,mi are the numbers of the pictures David should remove after the audience will make Ki moves (the number of the pictures removed is arbitrary, but each picture should be listed only once, and at least one picture should be removed on each turn). 30 | A description of the every next turn should begin with a new line. All numbers on each line should be separated by one or more spaces. After e iterations, all pictures except one should be removed. 31 | 32 | Sample Input 33 | 34 | 3 35 | Sample Output 36 | 37 | 3 1 3 7 9 38 | 5 2 4 6 8 39 | ************************************************************************/ 40 | 41 | /* 42 | * 1 < N < 101 43 | * N <= K < 300 44 | * Ki != Kj 45 | */ 46 | 47 | #include 48 | using namespace std; 49 | 50 | int main() 51 | { 52 | int N,K; 53 | cin >> N; 54 | K = N; 55 | cout << K << " "; 56 | for(int i = 0; i < N;i++) 57 | for(int j = 0; j < N;j++) 58 | if(i+j > N) 59 | cout << i*N+j+1 << " "; 60 | 61 | N%2 == 0?K++:K+=2; 62 | 63 | cout << endl << K << " "; 64 | K += 2; 65 | for(int i = 1 ; i < N; i++){ 66 | int j = N - i; 67 | cout << i*N+j+1 << " "; 68 | } 69 | 70 | for(int E = (N-1); E > 0; E--,K+=2){ 71 | cout << endl << K << " "; 72 | for(int i = 0 ; i <= E; i++){ 73 | int j = E - i; 74 | cout << i*N+j+1 << " "; 75 | } 76 | } 77 | 78 | return 0; 79 | } 80 | 81 | -------------------------------------------------------------------------------- /100-199/111.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | > File Name: 111.cpp 3 | > Author: Louis1992 4 | > Mail: zhenchaogan@gmail.com 5 | > Blog: http://gzc.github.io 6 | > Created Time: Thu Jul 9 17:39:35 2015 7 | ************************************************************************/ 8 | #include 9 | #include 10 | #include 11 | using namespace std; 12 | 13 | int compare(string s1, string s2) 14 | { 15 | if(s1.length() > s2.length()) return 1; 16 | else if(s1.length() < s2.length()) return -1; 17 | for(int i = 0;i < s1.length();i++) 18 | { 19 | if(s1[i] > s2[i]) return 1; 20 | if(s1[i] < s2[i]) return -1; 21 | } 22 | return 0; 23 | } 24 | 25 | string multiply(string num1, string num2) { 26 | string s(num1.length()+num2.length(),'0'); 27 | reverse(num1.begin(), num1.end()); 28 | reverse(num2.begin(), num2.end()); 29 | 30 | for(int i = 0;i < num1.length();i++) 31 | { 32 | int flag = 0; 33 | for(int j = 0;j < num2.length();j++) 34 | { 35 | int digit = s[i+j] - '0'; 36 | int num = (num1[i] - '0') * (num2[j] - '0'); 37 | int res = digit + num + flag; 38 | s[i+j] = (res % 10) + '0'; 39 | flag = res / 10; 40 | } 41 | 42 | int index = i + num2.size(); 43 | while(flag) 44 | { 45 | int digit = s[index] - '0'; 46 | int res = digit + flag; 47 | s[index] = (res % 10) + '0'; 48 | flag = res / 10; 49 | } 50 | } 51 | 52 | reverse(s.begin(), s.end()); 53 | 54 | while(s[0] == '0' && s.length() > 1) 55 | s = s.substr(1); 56 | return s; 57 | } 58 | 59 | string add(string num1, string num2) 60 | { 61 | int len = max(num1.length(),num2.length()); 62 | string res(len+1,'0'); 63 | int remain(0); 64 | int i = 0; 65 | reverse(num1.begin(), num1.end()); 66 | reverse(num2.begin(), num2.end()); 67 | while(i < len || remain != 0) 68 | { 69 | int tmp = remain + ( i >= num1.length()? 0 : (num1[i] - '0') ) + ( i >= num2.length()? 0 : (num2[i] - '0') ); 70 | res[i] = ('0' + tmp%10); 71 | remain = tmp/10; 72 | i++; 73 | } 74 | reverse(res.begin(), res.end()); 75 | while(res[0] == '0' && res.length() > 1) 76 | res = res.substr(1); 77 | return res; 78 | } 79 | 80 | string sub(string num1, string num2) { 81 | string s(max(num1.length(),num2.length())+1,'0'); 82 | bool flag(false); 83 | 84 | if(num1.length() > num2.length()) flag = false; 85 | else if(num1.length() < num2.length()) flag = true; 86 | else { 87 | if(num1 >= num2) flag = false; 88 | else flag = true; 89 | } 90 | 91 | reverse(num1.begin(), num1.end()); 92 | reverse(num2.begin(), num2.end()); 93 | if(flag) swap(num1, num2); 94 | 95 | bool lend(false); 96 | for(int i = 0;i < num1.length();i++) 97 | { 98 | int tmp = (num1[i] - '0') - ( i >= num2.length()? 0 : (num2[i] - '0') ); 99 | if(lend) tmp--; 100 | if(tmp < 0) { 101 | tmp += 10; 102 | lend = true; 103 | } else lend = false; 104 | s[i] = ('0'+tmp); 105 | } 106 | 107 | reverse(s.begin(), s.end()); 108 | 109 | while(s[0] == '0' && s.length() > 1) 110 | s = s.substr(1); 111 | if(flag) s.insert(0, "-"); 112 | return s; 113 | } 114 | 115 | string shiftRight(string s) 116 | { 117 | int remain(0); 118 | for(int i = 0;i < s.length();i++) 119 | { 120 | int d = (s[i] - '0'); 121 | s[i] = ('0' + d/2) + remain; 122 | if(d % 2 == 1) remain = 5; 123 | else remain = 0; 124 | } 125 | while(s[0] == '0' && s.length() > 1) 126 | s = s.substr(1); 127 | return s; 128 | } 129 | 130 | int main() 131 | { 132 | string x; cin >> x; 133 | string mid,ans("1"); 134 | string l("1"); 135 | string r((x.length()+1)/2,'0'); 136 | r = "1" + r; 137 | string one("1"); 138 | while(true){ 139 | mid = shiftRight(add(l,r)); 140 | int llen = mid.length()+mid.length()-1; 141 | int mlen = llen + 1; 142 | if(llen > x.length()){ 143 | r = sub(mid,one); 144 | }else if(mlen < x.length()){ 145 | ans = mid; 146 | l = add(mid,one); 147 | }else{ 148 | int cmp = compare(multiply(mid,mid),x); 149 | if(cmp > 0) 150 | { 151 | r = sub(mid,one); 152 | } else if(cmp < 0){ 153 | ans = mid; 154 | l = add(mid,one); 155 | } else { 156 | cout << mid; 157 | return 0; 158 | } 159 | } 160 | if(compare(l,r) > 0) 161 | break; 162 | } 163 | cout << ans; 164 | return 0; 165 | } -------------------------------------------------------------------------------- /100-199/111.java: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | 111. Very simple problem 3 | 4 | 5 | time limit per test: 0.25 sec. 6 | memory limit per test: 4096 KB 7 | 8 | You are given natural number X. Find such maximum integer number that it square is not greater than X. 9 | 10 | Input 11 | 12 | Input file contains number X (1≤X≤101000). 13 | 14 | Output 15 | 16 | Write answer in output file. 17 | 18 | Sample Input 19 | 20 | 16 21 | Sample Output 22 | 23 | 4 24 | ******************************************************/ 25 | 26 | import java.io.*; 27 | import java.math.*; 28 | import java.util.*; 29 | 30 | public class Solution { 31 | public static void main(String[] args) { 32 | BigInteger l = new BigInteger("1"); 33 | BigInteger r = (new BigInteger("10")).pow(500); 34 | BigInteger one = new BigInteger("1"); 35 | Scanner cin = new Scanner(new BufferedInputStream(System.in)); 36 | BigInteger x = cin.nextBigInteger(); 37 | BigInteger mid,ans; 38 | ans = new BigInteger("1"); 39 | while(true){ 40 | mid = (l.add(r)).shiftRight(1); 41 | if( (mid.pow(2)).compareTo(x) > 0){ 42 | r = mid.subtract(one); 43 | }else{ 44 | ans = mid; 45 | l = mid.add(one); 46 | } 47 | if(l.compareTo(r) > 0) 48 | break; 49 | } 50 | System.out.println(ans); 51 | } 52 | } -------------------------------------------------------------------------------- /100-199/112.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | 112. ab-ba 3 | 4 | 5 | time limit per test: 0.25 sec. 6 | memory limit per test: 4096 KB 7 | 8 | You are given natural numbers a and b. Find ab-ba. 9 | 10 | Input 11 | 12 | Input contains numbers a and b (1≤a,b≤100). 13 | 14 | Output 15 | 16 | Write answer to output. 17 | 18 | Sample Input 19 | 20 | 2 3 21 | Sample Output 22 | 23 | -1 24 | *****************************************************************************/ 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | using namespace std; 31 | 32 | string d2s(int d) 33 | { 34 | ostringstream ss; 35 | ss << d; 36 | return ss.str(); 37 | } 38 | 39 | string multiply(string num1, string num2) { 40 | string s(num1.length()+num2.length(),'0'); 41 | reverse(num1.begin(), num1.end()); 42 | reverse(num2.begin(), num2.end()); 43 | 44 | for(int i = 0;i < num1.length();i++) 45 | { 46 | int flag = 0; 47 | for(int j = 0;j < num2.length();j++) 48 | { 49 | int digit = s[i+j] - '0'; 50 | int num = (num1[i] - '0') * (num2[j] - '0'); 51 | int res = digit + num + flag; 52 | s[i+j] = (res % 10) + '0'; 53 | flag = res / 10; 54 | } 55 | 56 | int index = i + num2.size(); 57 | while(flag) 58 | { 59 | int digit = s[index] - '0'; 60 | int res = digit + flag; 61 | s[index] = (res % 10) + '0'; 62 | flag = res / 10; 63 | } 64 | } 65 | 66 | reverse(s.begin(), s.end()); 67 | 68 | while(s[0] == '0' && s.length() > 1) 69 | s = s.substr(1); 70 | return s; 71 | } 72 | 73 | string sub(string num1, string num2) { 74 | string s(max(num1.length(),num2.length())+1,'0'); 75 | bool flag(false); 76 | 77 | if(num1.length() > num2.length()) flag = false; 78 | else if(num1.length() < num2.length()) flag = true; 79 | else { 80 | if(num1 >= num2) flag = false; 81 | else flag = true; 82 | } 83 | 84 | reverse(num1.begin(), num1.end()); 85 | reverse(num2.begin(), num2.end()); 86 | if(flag) swap(num1, num2); 87 | 88 | bool lend(false); 89 | for(int i = 0;i < num1.length();i++) 90 | { 91 | int tmp = (num1[i] - '0') - ( i >= num2.length()? 0 : (num2[i] - '0') ); 92 | if(lend) tmp--; 93 | if(tmp < 0) { 94 | tmp += 10; 95 | lend = true; 96 | } else lend = false; 97 | s[i] = ('0'+tmp); 98 | } 99 | 100 | reverse(s.begin(), s.end()); 101 | 102 | while(s[0] == '0' && s.length() > 1) 103 | s = s.substr(1); 104 | if(flag) s.insert(0, "-"); 105 | return s; 106 | } 107 | 108 | string strpow(int x, int n) 109 | { 110 | string res("1"); 111 | string base = d2s(x); 112 | while(n > 0) 113 | { 114 | if(n % 2 == 1) 115 | res = multiply(res, base); 116 | base = multiply(base, base); 117 | n /= 2; 118 | } 119 | return res; 120 | } 121 | 122 | int main() 123 | { 124 | int a,b; cin >> a >> b; 125 | cout << sub(strpow(a,b), strpow(b,a)) << endl; 126 | return 0; 127 | } 128 | -------------------------------------------------------------------------------- /100-199/113.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | 113.Nearly prime numbers 3 | 4 | 5 | time limit per test: 0.25 sec. 6 | memory limit per test: 4096 KB 7 | 8 | Nearly prime number is an integer positive number for which it is possible to find such primes P1 and P2 that given number is equal to P1*P2. There is given a sequence on N integer positive numbers, you are to write a program that prints “Yes” if given number is nearly prime and “No” otherwise. 9 | 10 | Input 11 | 12 | Input file consists of N+1 numbers. First is positive integer N (1£N£10). Next N numbers followed by N. Each number is not greater than 109. All numbers separated by whitespace(s). 13 | 14 | Output 15 | 16 | Write a line in output file for each number of given sequence. Write “Yes” in it if given number is nearly prime and “No” in other case. 17 | 18 | Sample Input 19 | 20 | 1 21 | 6 22 | Sample Output 23 | 24 | Yes 25 | ********************************************************************************/ 26 | 27 | #include 28 | #include 29 | #include 30 | using namespace std; 31 | 32 | bool isPrime(int x) { 33 | if (x<2) return 0; 34 | for (int i=2;i*i<=x;i++) 35 | if (x%i==0) return false; 36 | return true; 37 | } 38 | 39 | 40 | int main() 41 | { 42 | int n = (int)sqrt(1000000000); 43 | int c = (int)sqrt(n); 44 | bool *bv = new bool[n+1]; 45 | memset(bv, true, n+1); 46 | for(int i = 2;i <= c;i++) 47 | if(bv[i]) 48 | for(int j = i*i;j < n; j += i) 49 | bv[j] = false; 50 | 51 | int N; 52 | cin >> N; 53 | for(int i = 0;i < N;i++) 54 | { 55 | int e; 56 | cin >> e; 57 | int low = (int)sqrt(e); 58 | bool flag(false); 59 | for(int j = 2;j <= low && !flag;j++) 60 | { 61 | if(bv[j] && e % j == 0) 62 | { 63 | int divide = e/j; 64 | if(divide <= c && bv[divide]) flag = true; 65 | if(divide > c && isPrime(divide)) flag = true; 66 | } 67 | } 68 | if(flag) cout << "Yes" << endl; 69 | else cout << "No" << endl; 70 | } 71 | 72 | return 0; 73 | } 74 | -------------------------------------------------------------------------------- /100-199/114.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | 114. Telecasting station 3 | 4 | 5 | time limit per test: 0.25 sec. 6 | memory limit per test: 4096 KB 7 | 8 | Every city in Berland is situated on Ox axis. The government of the country decided to build new telecasting station. After many experiments Berland scientists came to a conclusion that in any city citizens displeasure is equal to product of citizens amount in it by distance between city and TV-station. Find such point on Ox axis for station so that sum of displeasures of all cities is minimal. 9 | 10 | Input 11 | 12 | Input begins from line with integer positive number N (0 30 | #include 31 | #include 32 | using namespace std; 33 | 34 | struct point 35 | { 36 | int a; 37 | int b; 38 | point() 39 | { 40 | a = 0; 41 | b = 0; 42 | } 43 | bool operator < (const point& other) const 44 | { 45 | return a < other.a; 46 | } 47 | }; 48 | 49 | int main() 50 | { 51 | int N; cin >> N; 52 | vectorpoints(N); 53 | int total = 0; 54 | 55 | while(N--) 56 | { 57 | cin >> points[N].a; 58 | cin >> points[N].b; 59 | total += points[N].b; 60 | } 61 | 62 | sort(points.begin(), points.end()); 63 | int v = 0,i = 0; 64 | while(v < (total+1)/2) 65 | { 66 | v += points[i].b; 67 | i++; 68 | } 69 | cout << points[i-1].a << ".00000"; 70 | 71 | 72 | return 0; 73 | } 74 | -------------------------------------------------------------------------------- /100-199/115.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | 115. Calendar 3 | 4 | 5 | time limit per test: 0.25 sec. 6 | memory limit per test: 4096 KB 7 | 8 | First year of new millenium is gone away. In commemoration of it write a program that finds the name of the day of the week for any date in 2001. 9 | 10 | Input 11 | 12 | Input is a line with two positive integer numbers N and M, where N is a day number in month M. N and M is not more than 100. 13 | 14 | Output 15 | 16 | Write current number of the day of the week for given date (Monday – number 1, … , Sunday – number 7) or phrase “Impossible” if such date does not exist. 17 | 18 | Sample Input 19 | 20 | 21 10 21 | Sample Output 22 | 23 | 7 24 | ****************************************************************************/ 25 | 26 | #include 27 | using namespace std; 28 | 29 | int main() 30 | { 31 | int Month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; 32 | int D, M; 33 | cin >> D >> M; 34 | int start = 0; //2001 01 01 is Monday 35 | 36 | if(M < 1 || M > 12 || D < 1 || D > Month[M-1]) cout << "Impossible"; 37 | else { 38 | int total(start); 39 | for(int i = 0;i < M-1;i++) 40 | total += Month[i]; 41 | total += D; 42 | cout << 1 + (total-1)%7; 43 | } 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /100-199/116.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 116. Index of super-prime 3 | 4 | 5 | time limit per test: 0.25 sec. 6 | memory limit per test: 4096 KB 7 | 8 | Let P1, P2, … ,PN, … be a sequence of prime numbers. Super-prime number is such a prime number that its current number in prime numbers sequence is a prime number too. For example, 3 is a super-prime number, but 7 is not. Index of super-prime for number is 0 iff it is impossible to present it as a sum of few (maybe one) super-prime numbers, and if such presentation exists, index is equal to minimal number of items in such presentation. Your task is to find index of super-prime for given numbers and find optimal presentation as a sum of super-primes. 9 | 10 | Input 11 | 12 | There is a positive integer number in input. Number is not more than 10000. 13 | 14 | Output 15 | 16 | Write index I for given number as the first number in line. Write I super-primes numbers that are items in optimal presentation for given number. Write these I numbers in order of non-increasing. 17 | 18 | Sample Input 19 | 20 | 6 21 | Sample Output 22 | 23 | 2 24 | 3 3 25 | ************************************************************************/ 26 | #include 27 | #include 28 | #include 29 | using namespace std; 30 | 31 | int main() { 32 | 33 | int super[201] = { 3, 5, 11, 17, 31, 41, 59, 67, 83, 109, 127, 157, 179, 191, 211, 241, 277, 283, 331, 353, 367, 401, 431, 461, 509, 547, 563, 587, 599, 617, 709, 739, 773, 797, 859, 877, 919, 967, 991, 1031, 1063, 1087, 1153, 1171, 1201, 1217, 1297, 1409, 1433, 1447, 1471, 1499, 1523, 1597, 1621, 1669, 1723, 1741, 1787, 1823, 1847, 1913, 2027, 2063, 2081, 2099, 2221, 2269, 2341, 2351, 2381, 2417, 2477, 2549, 2609, 2647, 2683, 2719, 2749, 2803, 2897, 2909, 3001, 3019, 3067, 3109, 3169, 3229, 3259, 3299, 3319, 3407, 3469, 3517, 3559, 3593, 3637, 3733, 3761, 3911, 3943, 4027, 4091, 4133, 4153, 4217, 4273, 4339, 4397, 4421, 4463, 4517, 4549, 4567, 4663, 4759, 4787, 4801, 4877, 4933, 4943, 5021, 5059, 5107, 5189, 5281, 5381, 5441, 5503, 5557, 5623, 5651, 5701, 5749, 5801, 5851, 5869, 6037, 6113, 6217, 6229, 6311, 6323, 6353, 6361, 6469, 6599, 6653, 6661, 6691, 6823, 6841, 6863, 6899, 7057, 7109, 7193, 7283, 7351, 7417, 7481, 7523, 7607, 7649, 7699, 7753, 7841, 7883, 8011, 8059, 8101, 8117, 8221, 8233, 8287, 8377, 8389, 8513, 8527, 8581, 8719, 8747, 8761, 8807, 8849, 8923, 8999, 9041, 9103, 9293, 9319, 9403, 9461, 9539, 9619, 9661, 9739, 9833, 9859, 9923, 9973 }; 34 | 35 | int N; cin >> N; 36 | int *dp = new int[N+1]; 37 | int *path = new int[N+1]; 38 | fill(dp,dp+N+1,INT_MAX); 39 | fill(path,path+N+1,-1); 40 | dp[0] = 0; 41 | 42 | for(int i = 0;i <= N;i++) 43 | { 44 | for(int j = 0;j < 201 && (i + super[j] <= N);j++) 45 | { 46 | if(dp[i] < INT_MAX && dp[i+super[j]] > dp[i]+1) 47 | { 48 | dp[i + super[j]] = dp[i]+1; 49 | path[i+super[j]] = i; 50 | } 51 | } 52 | } 53 | 54 | if(dp[N] != INT_MAX) { 55 | cout << dp[N] << endl; 56 | while(N > 0) { 57 | cout << N - path[N] << " "; 58 | N = path[N]; 59 | } 60 | } else { 61 | cout << 0; 62 | } 63 | 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /100-199/117.cpp: -------------------------------------------------------------------------------- 1 | /********************************************************************************** 2 | 117. Counting 3 | 4 | 5 | time limit per test: 0.25 sec. 6 | memory limit per test: 4096 KB 7 | 8 | Find amount of numbers for given sequence of integer numbers such that after raising them to the M-th power they will be divided by K. 9 | 10 | Input 11 | 12 | Input consists of two lines. There are three integer numbers N, M, K (0 28 | using namespace std; 29 | 30 | int modexp(int a,int b,int n) 31 | { 32 | int ret=1; 33 | int tmp=a; 34 | while(b) 35 | { 36 | //基数存在 37 | if(b&0x1) ret=ret*tmp%n; 38 | tmp=tmp*tmp%n; 39 | b>>=1; 40 | } 41 | return ret; 42 | } 43 | 44 | int main() 45 | { 46 | int N,M,K; 47 | cin >> N >> M >> K; 48 | int ans(0); 49 | 50 | for(int i = 0;i < N;i++) 51 | { 52 | int tmp; 53 | cin >> tmp; 54 | if (modexp(tmp, M, K) == 0) 55 | ans++; 56 | } 57 | cout << ans; 58 | 59 | return 0; 60 | } 61 | -------------------------------------------------------------------------------- /100-199/118.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************ 2 | 3 | 118. Digital Root 4 | 5 | 6 | time limit per test: 0.25 sec. 7 | memory limit per test: 4096 KB 8 | 9 | Let f(n) be a sum of digits for positive integer n. If f(n) is one-digit number then it is a digital root for n and otherwise digital root of n is equal to digital root of f(n). For example, digital root of 987 is 6. Your task is to find digital root for expression A1*A2*…*AN + A1*A2*…*AN-1 + … + A1*A2 + A1. 10 | 11 | Input 12 | 13 | Input file consists of few test cases. There is K (1<=K<=5) in the first line of input. Each test case is a line. Positive integer number N is written on the first place of test case (N<=1000). After it there are N positive integer numbers (sequence A). Each of this numbers is non-negative and not more than 109. 14 | 15 | Output 16 | 17 | Write one line for every test case. On each line write digital root for given expression. 18 | 19 | Sample Input 20 | 21 | 1 22 | 3 2 3 4 23 | Sample Output 24 | 25 | 5 26 | 27 | ************************************************************/ 28 | 29 | #include 30 | using namespace std; 31 | 32 | int main() 33 | { 34 | int N; cin >> N; 35 | while(N--) 36 | { 37 | int d;cin >> d; 38 | int sum(0); 39 | int tmp(1); 40 | while(d--) 41 | { 42 | int a; cin >> a; 43 | a %= 9; 44 | tmp *= a; 45 | tmp %= 9; 46 | sum += tmp; 47 | } 48 | sum %= 9; 49 | if(sum == 0) cout << 9 << endl; 50 | else cout << sum << endl; 51 | } 52 | 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /100-199/119.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 119. Magic Pairs 3 | 4 | 5 | time limit per test: 0.25 sec. 6 | memory limit per test: 4096 KB 7 | 8 | “Prove that for any integer X and Y if 5X+4Y is divided by 23 than 3X+7Y is divided by 23 too.” The task is from city Olympiad in mathematics in Saratov, Russia for schoolchildren of 8-th form. 2001-2002 year. 9 | 10 | 11 | For given N and pair (A0, B0) find all pairs (A, B) such that for any integer X and Y if A0X+B0Y is divided by N then AX+BY is divided by N too (0<=A,B 33 | #include 34 | using namespace std; 35 | 36 | int main() { 37 | 38 | pair ans[10010]; 39 | int n,a0,b0; 40 | scanf("%d%d%d",&n,&a0,&b0); 41 | 42 | int i = a0 %= n; 43 | int j = b0 %= n; 44 | int num = 0; 45 | 46 | do { 47 | ans[num++] = make_pair(i, j); 48 | i = (i+a0)%n; 49 | j = (j+b0)%n; 50 | } while(i != a0 || j != b0); 51 | 52 | sort(ans, ans+num); 53 | printf("%d\n",num); 54 | for(i = 0;i < num;i++) 55 | printf("%d %d\n",ans[i].first,ans[i].second); 56 | 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /100-199/120.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 120. Archipelago 3 | 4 | 5 | time limit per test: 0.25 sec. 6 | memory limit per test: 4096 KB 7 | 8 | Archipelago Ber-Islands consists of N islands that are vertices of equiangular and equilateral N-gon. Islands are clockwise numerated. Coordinates of island N1 are (x1, y1), and island N2 – (x2, y2). Your task is to find coordinates of all N islands. 9 | 10 | Input 11 | 12 | In the first line of input there are N, N1 and N2 (3£ N£ 150, 1£ N1,N2£N, N1¹N2) separated by spaces. On the next two lines of input there are coordinates of island N1 and N2 (one pair per line) with accuracy 4 digits after decimal point. Each coordinate is more than -2000000 and less than 2000000. 13 | 14 | Output 15 | 16 | Write N lines with coordinates for every island. Write coordinates in order of island numeration. Write answer with 6 digits after decimal point. 17 | 18 | Sample Input 19 | 20 | 4 1 3 21 | 1.0000 0.0000 22 | 1.0000 2.0000 23 | Sample Output 24 | 25 | 1.000000 0.000000 26 | 0.000000 1.000000 27 | 1.000000 2.000000 28 | 2.000000 1.000000 29 | ************************************************************************/ 30 | #include 31 | #include 32 | #include 33 | 34 | #define pf(x) ((x)*(x)) 35 | const double EPS=1e-9; 36 | using namespace std; 37 | 38 | void rotate(double &vx,double &vy,double theta) 39 | { 40 | double tx=cos(theta)*vx+sin(theta)*vy; 41 | double ty=cos(theta)*vy-sin(theta)*vx; 42 | vx=tx,vy=ty; 43 | } 44 | 45 | int main() 46 | { 47 | int n,n1,n2,i; 48 | double a,b,r,d,vx,vy,x1,y1,x2,y2,h,dx,dy,theta; 49 | scanf("%d%d%d",&n,&n1,&n2); 50 | scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2); 51 | 52 | if(n1>n2) 53 | { 54 | swap(n1,n2); 55 | swap(x1,x2); 56 | swap(y1,y2); 57 | } 58 | d=sqrt(pf(x2-x1)+pf(y2-y1)); 59 | a=(x1+x2)/2; 60 | b=(y1+y2)/2; 61 | 62 | if(2*(n2-n1)!=n) 63 | { 64 | theta=2*M_PI/n*(n2-n1); 65 | if(theta>M_PI) 66 | theta=2*M_PI-theta; 67 | r=d*sin((M_PI-theta)/2)/sin(theta); //正弦定理 68 | vx=x2-x1,vy=y2-y1; 69 | h=sqrt(r*r-pf(d/2)); 70 | 71 | //相似三角形 72 | dx=-h*vy/d; 73 | dy=h*vx/d; 74 | 75 | a+=dx,b+=dy; 76 | if(((x1-a)*(y2-b)-(x2-a)*(y1-b))*(2*(n2-n1)-n)<0) 77 | a-=2*dx,b-=2*dy; 78 | } 79 | 80 | vx=x1-a,vy=y1-b; 81 | theta=2*M_PI/n; 82 | rotate(vx,vy,-theta*n1); 83 | for(i=1;i<=n;++i) 84 | { 85 | rotate(vx,vy,theta); 86 | if(abs(vx+a)1. You have to find S - the sum of the first K Fibonacci numbers. 9 | 10 | Input 11 | 12 | First line contains natural number K (0 27 | using namespace std; 28 | 29 | int main() 30 | { 31 | int k; 32 | cin >> k; 33 | 34 | int a(1),b(1),c(0); 35 | for(int i = 0;i < k;i++) 36 | { 37 | c = a+b; 38 | a = b; 39 | b = c; 40 | } 41 | 42 | cout << c-1; 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /100-199/124.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 124. Broken line 3 | 4 | 5 | time limit per test: 0.25 sec. 6 | memory limit per test: 4096 KB 7 | 8 | There is a closed broken line on a plane with sides parallel to coordinate axes, without self-crossings and self-contacts. The broken line consists of K segments. You have to determine, whether a given point with coordinates (X0,Y0) is inside this closed broken line, outside or belongs to the broken line. 9 | 10 | Input 11 | 12 | The first line contains integer K (4 Ј K Ј 10000) - the number of broken line segments. Each of the following N lines contains coordinates of the beginning and end points of the segments (4 integer xi1,yi1,xi2,yi2; all numbers in a range from -10000 up to 10000 inclusive). Number separate by a space. The segments are given in random order. Last line contains 2 integers X0 and Y0 - the coordinates of the given point delimited by a space. (Numbers X0, Y0 in a range from -10000 up to 10000 inclusive). 13 | 14 | Output 15 | 16 | The first line should contain: 17 | 18 | INSIDE - if the point is inside closed broken line, 19 | 20 | OUTSIDE - if the point is outside, 21 | 22 | BORDER - if the point belongs to broken line. 23 | 24 | Sample Input 25 | 26 | 4 27 | 0 0 0 3 28 | 3 3 3 0 29 | 0 3 3 3 30 | 3 0 0 0 31 | 2 2 32 | Sample Output 33 | 34 | INSIDE 35 | ************************************************************************/ 36 | #include 37 | #include 38 | using namespace std; 39 | 40 | const int maxn(10030); 41 | int x1[maxn],x2[maxn],y1[maxn],y2[maxn]; 42 | 43 | int main() 44 | { 45 | int n; 46 | cin >> n; 47 | for (int i=1;i<=n;i++) 48 | { 49 | cin >> x1[i] >> y1[i] >> x2[i] >> y2[i]; 50 | if (x1[i]==x2[i] && y1[i] > y2[i]) 51 | swap(y1[i], y2[i]); 52 | if (y1[i]==y2[i] && x1[i] > x2[i]) 53 | swap(x1[i],x2[i]); 54 | } 55 | 56 | int x0,y0; 57 | cin >> x0 >> y0; 58 | for (int i=1;i<=n;i++) 59 | { 60 | if ((x1[i]==x2[i]) && (x1[i]==x0) && (y1[i]<=y0) && (y2[i]>=y0)) 61 | { 62 | cout << "BORDER"; 63 | return 0; 64 | } 65 | if ((y1[i]==y2[i]) && (y1[i]==y0) && (x1[i]<=x0) && (x2[i]>=x0)) 66 | { 67 | cout << "BORDER"; 68 | return 0; 69 | } 70 | } 71 | 72 | int t=0; 73 | for (int i=1;i<=n;i++) 74 | if ((y1[i]==y2[i]) && (y1[i]>y0) && (x1[i]=x0)) t++; 75 | 76 | if (t % 2 == 1) cout << "INSIDE"; 77 | else cout << "OUTSIDE"; 78 | 79 | return 0; 80 | } -------------------------------------------------------------------------------- /100-199/125.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 125. Shtirlits 3 | 4 | 5 | time limit per test: 0.25 sec. 6 | memory limit per test: 4096 KB 7 | 8 | 9 | There is a checkered field of size N x N cells (1 Ј N Ј 3). Each cell designates the territory of a state (i.e. N2 states). Each state has an army. Let A [i, j] be the number of soldiers in the state which is located on i-th line and on j-th column of the checkered field (1£i£N, 1£j£N, 0 £ A[i, j] £ 9). For each state the number of neighbors, B [i, j], that have a larger army, is known. The states are neighbors if they have a common border (i.e. 0 £ B[i, j] £ 4). Shtirlits knows matrix B. He has to determine the number of armies for all states (i.e. to find matrix A) using this information for placing forces before the war. If there are more than one solution you may output any of them. 10 | 11 | Input 12 | 13 | The first line contains a natural number N. Following N lines contain the description of matrix B - N numbers in each line delimited by spaces. 14 | 15 | Output 16 | 17 | If a solution exists, the output file should contain N lines, which describe matrix A. Each line will contain N numbers delimited by spaces. If there is no solution, the file should contain NO SOLUTION. 18 | 19 | Sample Input 20 | 21 | 3 22 | 1 2 1 23 | 1 2 1 24 | 1 1 0 25 | Sample Output 26 | 27 | 1 2 3 28 | 1 4 5 29 | 1 6 7 30 | ************************************************************************/ 31 | #include 32 | using namespace std; 33 | 34 | int n; 35 | int a[4][4]; 36 | int b[4][4]; 37 | 38 | bool dfs(int ci, int cj) 39 | { 40 | if(ci >= n) 41 | { 42 | if (a[n-1][n-1] == 0) return true; 43 | return false; 44 | } 45 | int ni,nj; 46 | if(cj == n-1) { 47 | ni = ci+1; 48 | nj = 0; 49 | } else { 50 | ni = ci; 51 | nj = cj+1; 52 | } 53 | 54 | for(int k = 0;k <= 9;k++) 55 | { 56 | b[ci][cj] = k; 57 | int lefti(-1),leftj(-1),upi(-1),upj(-1); 58 | int r1(-1),c1(-1),r2(-1),c2(-1); 59 | bool f1(false),f2(false); 60 | bool check = true; 61 | 62 | if(cj != 0 && n > 1) 63 | { 64 | lefti = ci; 65 | leftj = cj-1; 66 | if(k > b[lefti][leftj]) 67 | { 68 | r1 = lefti; 69 | c1 = leftj; 70 | } else if(k < b[lefti][leftj]) { 71 | r1 = ci; 72 | c1 = cj; 73 | } 74 | } 75 | 76 | if(ci != 0 && n > 1) 77 | { 78 | upi = ci-1; 79 | upj = cj; 80 | if(k > b[upi][upj]) 81 | { 82 | r2 = upi; 83 | c2 = upj; 84 | } else if(k < b[upi][upj]) { 85 | r2 = ci; 86 | c2 = cj; 87 | } 88 | } 89 | 90 | if(upi != -1) 91 | { 92 | if(a[upi][upj] > 1) return false; 93 | if(a[upi][upj] == 1 && k <= b[upi][upj]) continue; 94 | } 95 | 96 | if(lefti != -1) 97 | { 98 | if(a[lefti][leftj] > 2) return false; 99 | if(a[lefti][leftj] == 2 && ci == n-1) return false; 100 | if(a[lefti][leftj] == 2 && k <= b[lefti][leftj]) continue; 101 | if(a[lefti][leftj] == 1 && ci == n-1 && k <= b[lefti][leftj]) continue; 102 | } 103 | 104 | 105 | if(r1 != -1) 106 | { 107 | if(a[r1][c1] > 0) 108 | { 109 | 110 | a[r1][c1]--; 111 | f1 = true; 112 | } 113 | else check = false; 114 | } 115 | 116 | if(r2 != -1) 117 | { 118 | if(a[r2][c2] > 0) 119 | { 120 | a[r2][c2]--; 121 | f2 = true; 122 | } 123 | else check = false; 124 | } 125 | 126 | bool fff = false; 127 | 128 | if(check) 129 | { 130 | fff = dfs(ni, nj); 131 | if(fff) 132 | return true; 133 | } 134 | if(f1) a[r1][c1]++; 135 | if(f2) a[r2][c2]++; 136 | 137 | } 138 | 139 | return false; 140 | } 141 | 142 | int main() { 143 | cin >> n; 144 | for(int i = 0;i < n;i++) 145 | for(int j = 0;j < n;j++) 146 | cin >> a[i][j]; 147 | 148 | bool fff = dfs(0,0); 149 | if(n == 1) 150 | { 151 | if(a[0][0] > 0) cout << "NO SOLUTION"; 152 | else cout << 0 << endl; 153 | return 0; 154 | } 155 | if(!fff) { 156 | cout << "NO SOLUTION"; 157 | return 0; 158 | } else { 159 | for(int i = 0;i < n;i++) 160 | { 161 | for(int j = 0;j < n;j++) 162 | { 163 | cout << b[i][j] << " "; 164 | } 165 | cout << endl; 166 | } 167 | } 168 | return 0; 169 | } -------------------------------------------------------------------------------- /100-199/126.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************ 2 | 126. Boxes 3 | 4 | 5 | time limit per test: 0.25 sec. 6 | memory limit per test: 4096 KB 7 | 8 | There are two boxes. There are A balls in the first box, and B balls in the second box (0 < A + B < 2147483648). It is possible to move balls from one box to another. From one box into another one should move as many balls as the other box already contains. You have to determine, whether it is possible to move all balls into one box. 9 | 10 | Input 11 | 12 | The first line contains two integers A and B, delimited by space. 13 | 14 | Output 15 | 16 | First line should contain the number N - the number of moves which are required to move all balls into one box, or -1 if it is impossible. 17 | 18 | Sample Input 19 | 20 | Sample Output 21 | 22 | 2 6 23 | Sample Output 24 | 25 | 2 26 | ************************************************************/ 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | using namespace std; 33 | 34 | int gcd(int a, int b) 35 | { 36 | if(a == 0) return b; 37 | return gcd(b%a, a); 38 | } 39 | 40 | int main() 41 | { 42 | int a,b; cin >> a >> b; 43 | int v = (a+b)/gcd(min(a,b),max(a,b)); 44 | 45 | for(int i = 0;i < 32;i++) 46 | { 47 | if(abs(pow(2, i) - v) < 1e-5) 48 | { 49 | cout << i; 50 | return 0; 51 | } 52 | } 53 | 54 | cout << -1; 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /100-199/127.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************************************** 2 | 127. Telephone directory 3 | 4 | 5 | time limit per test: 0.25 sec. 6 | memory limit per test: 4096 KB 7 | 8 | CIA has decided to create a special telephone directory for its agents. The first 2 pages of the directory contain the name of the directory and instructions for agents, telephone number records begin on the third page. Each record takes exactly one line and consists of 2 parts: the phone number and the location of the phone. The phone number is 4 digits long. Phone numbers cannot start with digits 0 and 8. Each page of the telephone directory can contain not more then K lines. Phone numbers should be sorted in increasing order. For the first phone number with a new first digit, the corresponding record should be on a new page of the phone directory. You are to write a program, that calculates the minimal number P pages in the directory. For this purpose, CIA gives you the list of numbers containing N records, but since the information is confidential, without the phones locations. 9 | 10 | Input 11 | 12 | The first line contains a natural number K (0 < K < 255) - the maximum number of lines that one page can contain. The second line contains a natural N (0 < N < 8000) - number of phone numbers supplied. Each of following N lines contains a number consisting of 4 digits - phone numbers in any order, and it is known, that numbers in this list cannot repeat. 13 | 14 | Output 15 | 16 | First line should contain a natural number P - the number of pages in the telephone directory. 17 | 18 | Sample Input 19 | 20 | 5 21 | 10 22 | 1234 23 | 5678 24 | 1345 25 | 1456 26 | 1678 27 | 1111 28 | 5555 29 | 6789 30 | 6666 31 | 5000 32 | 33 | Sample Output 34 | 35 | 5 36 | **********************************************************************************/ 37 | #include 38 | #include 39 | using namespace std; 40 | 41 | int main() 42 | { 43 | int K,N,ans(2); 44 | cin >> K >> N; 45 | int a[10] = {0}; 46 | 47 | while(N--) 48 | { 49 | int tmp; 50 | cin >> tmp; 51 | a[tmp/1000]++; 52 | } 53 | 54 | for(int i = 0;i <= 9;i++) 55 | ans += (int)ceil(a[i]*1.0/K); 56 | 57 | cout << ans; 58 | 59 | return 0; 60 | } 61 | -------------------------------------------------------------------------------- /100-199/130.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | 130. Circle 3 | 4 | 5 | time limit per test: 0.25 sec. 6 | memory limit per test: 4096 KB 7 | 8 | On a circle border there are 2k different points A1, A2, ..., A2k, located contiguously. These points connect k chords so that each of points A1, A2, ..., A2k is the end point of one chord. Chords divide the circle into parts. You have to find N - the number of different ways to connect the points so that the circle is broken into minimal possible amount of parts P. 9 | 10 | Input 11 | 12 | The first line contains the integer k (1 <= k <= 30). 13 | 14 | Output 15 | 16 | The first line should contain two numbers N and P delimited by space. 17 | 18 | Sample Input 19 | 20 | 2 21 | Sample Output 22 | 23 | 2 3 24 | *******************************************************/ 25 | 26 | #include 27 | #include 28 | #include 29 | using namespace std; 30 | 31 | long long p[31]; 32 | 33 | int main(){ 34 | 35 | int k;cin >> k; 36 | fill(p, p+31, 0); 37 | p[0]=1; 38 | for(int i = 1;i <= k;i++) 39 | for(int j = 0;j < i;j++) 40 | p[i] += p[j]*p[i-j-1]; 41 | cout << p[k] << " " << k+1; 42 | 43 | return 0; 44 | } -------------------------------------------------------------------------------- /100-199/131.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 131. Hardwood floor 3 | 4 | 5 | time limit per test: 0.25 sec. 6 | memory limit per test: 4096 KB 7 | 8 | The banquet hall of Computer Scientists' Palace has a rectangular form of the size M x N (1<=M<=9, 1<=N<=9). It is necessary to lay hardwood floors in the hall. There are wood pieces of two forms: 9 | 1) rectangles (2x1) 10 | 2) corners (squares 2x2 without one 1x1 square) 11 | You have to determine X - the number of ways to cover the banquet hall. 12 | Remarks. The number of pieces is large enough. It is not allowed to leave empty places, or to cover any part of a surface twice, or to saw pieces. 13 | Input 14 | 15 | The first line contains natural number M. The second line contains a natural number N. 16 | 17 | Output 18 | 19 | First line should contain the number X, or 0 if there are no solutions. 20 | 21 | Sample Input 22 | 23 | 2 3 24 | Sample Output 25 | 26 | 5 27 | ************************************************************************/ 28 | #include 29 | #include 30 | using namespace std; 31 | 32 | int n, m, x; 33 | long long f[10][1 << 10]; 34 | 35 | void dfs (int k, int last, int now, int b1, int b2) { 36 | if (k == m){ 37 | if(!b1 && !b2) 38 | f[x][now] += f[x - 1][last]; 39 | return; 40 | } 41 | if (!b1 && !b2) { 42 | dfs (k + 1, last << 1 , now << 1 | 1, 0, 0); 43 | dfs (k + 1, last << 1 , now << 1 | 1, 1, 0); 44 | dfs (k + 1, last << 1 , now << 1 | 1, 0, 1); 45 | } 46 | if (!b1) 47 | dfs (k + 1, last << 1 , now << 1 | b2, 1, 1); 48 | if (!b2) { 49 | dfs (k + 1, last << 1 | (1-b1), now << 1 | 1, 0, 1); 50 | dfs (k + 1, last << 1 | (1-b1), now << 1 | 1, 1, 1); 51 | } 52 | dfs (k + 1, last << 1 | (1-b1), now << 1 | b2, 0, 0); 53 | } 54 | 55 | int main() { 56 | cin >> n >> m; 57 | if (n < m) swap (n, m); 58 | f[0][ (1 << m) - 1] = 1; 59 | for ( x = 1; x <= n; x++) 60 | dfs (0, 0, 0, 0, 0); 61 | 62 | cout << f[n][(1 << m) - 1]; 63 | } -------------------------------------------------------------------------------- /100-199/133.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************** 2 | 133. Border 3 | 4 | 5 | time limit per test: 0.25 sec. 6 | memory limit per test: 4096 KB 7 | 8 | Along the border between states A and B there are N defence outposts. For every outpost k, the interval [Ak,Bk] which is guarded by it is known. Because of financial reasons, the president of country A decided that some of the outposts should be abandoned. In fact, all the redundant outposts will be abandoned. An outpost i is redundant if there exists some outpost j such that Aj 32 | #include 33 | #include 34 | using namespace std; 35 | 36 | struct Interval { 37 | int start; 38 | int end; 39 | Interval() : start(0), end(0) {} 40 | Interval(int s, int e) : start(s), end(e) {} 41 | }; 42 | 43 | bool compareInterval(Interval a, Interval b) 44 | { 45 | return (a.start < b.start); 46 | } 47 | 48 | int merge(vector &intervals) { 49 | 50 | int res(0); 51 | sort(intervals.begin(),intervals.end(),compareInterval); 52 | 53 | Interval now = intervals[0]; 54 | for(int i = 1;i < intervals.size();i++) 55 | { 56 | Interval then = intervals[i]; 57 | 58 | if(now.end >= then.start) 59 | { 60 | if(now.end > then.end) res++; 61 | now.end = max(now.end, then.end); 62 | } else { 63 | now = then; 64 | } 65 | } 66 | return res; 67 | } 68 | 69 | int main() 70 | { 71 | int N;cin >> N; 72 | vector intervals; 73 | while(N--) 74 | { 75 | int a,b; 76 | cin >> a; 77 | cin >> b; 78 | intervals.push_back(Interval(a, b)); 79 | } 80 | merge(intervals); 81 | return 0; 82 | } -------------------------------------------------------------------------------- /100-199/134.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 134. Centroid 3 | 4 | 5 | time limit per test: 0.25 sec. 6 | memory limit per test: 4096 KB 7 | 8 | You are given an undirected connected graph, with N vertices and N-1 edges (a tree). You must find the centroid(s) of the tree. 9 | In order to define the centroid, some integer value will be assosciated to every vertex. Let's consider the vertex k. If we remove the vertex k from the tree (along with its adjacent edges), the remaining graph will have only N-1 vertices and may be composed of more than one connected components. Each of these components is (obviously) a tree. The value associated to vertex k is the largest number of vertices contained by some connected component in the remaining graph, after the removal of vertex k. All the vertices for which the associated value is minimum are considered centroids. 10 | 11 | Input 12 | 13 | The first line of the input contains the integer number N (1<=N<=16 000). The next N-1 lines will contain two integers, a and b, separated by blanks, meaning that there exists an edge between vertex a and vertex b. 14 | 15 | Output 16 | 17 | You should print two lines. The first line should contain the minimum value associated to the centroid(s) and the number of centroids. The second line should contain the list of vertices which are centroids, sorted in ascending order. 18 | 19 | Sample Input 20 | 21 | 7 22 | 1 2 23 | 2 3 24 | 2 4 25 | 1 5 26 | 5 6 27 | 6 7 28 | Sample Output 29 | 30 | 3 1 31 | 1 32 | ************************************************************************/ 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | using namespace std; 39 | 40 | const int MAXX=16010; 41 | 42 | int dp[MAXX];//dp[i]以i为根的子树总共包含的节点数。 43 | int weight[MAXX]; 44 | bool vis[MAXX]; 45 | vector tree[MAXX];//存树的逻辑结构 46 | int n; 47 | int res(INT_MAX); 48 | 49 | void DFS(int root) 50 | { 51 | int v; 52 | int localmax(-1); 53 | vis[root]=true; 54 | for(int i=0;i> n; 74 | 75 | for(int i = 1;i < n;i++) 76 | { 77 | cin >> x >> y; 78 | tree[x].push_back(y); 79 | tree[y].push_back(x); 80 | } 81 | 82 | DFS(1); 83 | int num(0); 84 | vector nums; 85 | for(int i = 1;i <= n;i++) 86 | { 87 | if(weight[i] == res) 88 | { 89 | num++; 90 | nums.push_back(i); 91 | } 92 | } 93 | cout << res << " " << num << endl; 94 | for(int i = 0;i < nums.size();i++) 95 | cout << nums[i] << endl; 96 | return 0; 97 | } -------------------------------------------------------------------------------- /100-199/135.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | 135. Drawing Lines 3 | 4 | 5 | time limit per test: 0.25 sec. 6 | memory limit per test: 4096 KB 7 | 8 | Little Johnny likes to draw a lot. A few days ago he painted lots of straight lines on his sheet of paper. Then he counted in how many zones the sheet of paper was split by these lines. He noticed that this number is not always the same. For instance, if he draws 2 lines, the sheet of paper could be split into 4, 3 or even 2 (if the lines are identical) zones. Since he is a very curious kid, he would like to know which is the maximum number of zones into which he can split the sheet of paper, if he draws N lines. The sheet of paper is to be considered a very large (=infinite) rectangle. 9 | 10 | Input 11 | 12 | The input file will contain an integer number: N (0<=N<=65535). 13 | 14 | Output 15 | 16 | You should output one integer: the maximum number of zones into which the sheet of paper can be split if Johnny draws N lines. 17 | 18 | Sample Input #1 19 | 20 | 0 21 | Sample Output #1 22 | 23 | 1 24 | Sample Input #2 25 | 26 | 1 27 | Sample Output #2 28 | 29 | 2 30 | ************************************************************************/ 31 | 32 | #include 33 | using namespace std; 34 | 35 | int main() 36 | { 37 | int N; 38 | cin >> N; 39 | cout << (long long)N*(long long)(N+1)/2 + 1; 40 | 41 | return 0; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /100-199/139.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 139. Help Needed! 3 | 4 | 5 | time limit per test: 0.25 sec. 6 | memory limit per test: 4096 KB 7 | 8 | Little Johnny likes puzzles a lot! Just a few days ago, he found out about the 'traditional' 4x4 puzzle. For this puzzle, you have all the numbers from 0 to 15 arranged in 4 rows and 4 columns. You are allowed to switch two adjacent elements (horizontally or vertically), only if one of them has the value 0. The purpose of the puzzle is to reach the following final state: 9 | 10 | 1 2 3 4 11 | 5 6 7 8 12 | 9 10 11 12 13 | 13 14 15 0 14 | 15 | Given the initial state of the puzzle, you have to decide whether there exists a sequence of moves which brings the puzzle into the final state. 16 | 17 | Input 18 | 19 | The input will consist of 4 lines, each of them containing 4 integers, describing the initial state of the puzzle. 20 | 21 | Output 22 | 23 | For every initial state, you should print "YES" if the final state can be reached after several moves or "NO", if such a thing is impossible. 24 | 25 | Sample Input #1 26 | 27 | 1 2 3 4 28 | 5 6 7 8 29 | 9 10 11 0 30 | 13 14 15 12 31 | Sample Output #1 32 | 33 | YES 34 | Sample Input #2 35 | 36 | 2 1 3 4 37 | 5 6 7 8 38 | 9 10 11 12 39 | 0 13 14 15 40 | Sample Output #2 41 | 42 | NO 43 | ************************************************************************/ 44 | #include 45 | using namespace std; 46 | 47 | int main() { 48 | int a[16]; 49 | int row = 0; 50 | for(int i = 0;i < 16;i++) 51 | { 52 | cin >> a[i]; 53 | if(a[i] == 0) 54 | row = i/4; 55 | } 56 | row = 3 - row; 57 | 58 | int inv = 0; 59 | for(int i = 0;i < 15;i++) 60 | for(int j = i + 1;j < 16;j++) 61 | if(a[j] < a[i] && a[j] != 0) 62 | inv++; 63 | 64 | if( (inv % 2 == 0 && row % 2 == 0) || (inv % 2 == 1 && row % 2 == 1)) 65 | cout << "YES"; 66 | else 67 | cout << "NO"; 68 | 69 | 70 | return 0; 71 | } 72 | -------------------------------------------------------------------------------- /100-199/142.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 142. Keyword 3 | 4 | 5 | time limit per test: 0.5 sec. 6 | memory limit per test: 16384 KB 7 | 8 | Kevin has invented a new algorithm to crypt and decrypt messages, which he thinks is unbeatable. The algorithm uses a very large key-string, out of which a keyword is found out after applying the algorithm. Then, based on this keyword, the message is easily crypted or decrypted. So, if one would try to decrypt some messages crypted with this algorithm, then knowing the keyword would be enough. Someone has found out how the keyword is computed from the large key-string, but because he is not a very experienced computer programmer, he needs your help. The key-string consists of N characters from the set {'a','b'}. The keyword is the shortest non-empty string made up of the letters 'a' and 'b', which is not contained as a contiguous substring (also called subsequence) inside the key-string. It is possible that more than one such string exists, but the algorithm is designed in such a way that any of these strings can be used as a keyword. Given the key-string, your task is to find one keyword. 9 | 10 | Input 11 | 12 | The first line contains the integer number N, the number of characters inside the key-string (1 <= N <= 500 000). The next line contains N characters from the set {'a','b'} representing the string. 13 | 14 | Output 15 | 16 | The first line of output should contain the number of characters of the keyword. The second line should contain the keyword. 17 | 18 | Sample Input 19 | 20 | 11 21 | aabaaabbbab 22 | Sample Output 23 | 24 | 4 25 | aaaa 26 | ************************************************************************/ 27 | #include 28 | #include 29 | char ch; 30 | int g[1 << 19]; 31 | bool f[20][1 << 19]; 32 | int k, n, len, fid; 33 | 34 | int main() { 35 | scanf ("%d", &n); 36 | ch = getchar(); 37 | for (int i = 1; i <= n; i++) 38 | g[i] = (getchar() == 'a'); 39 | 40 | for (int i = 1; i <= n; i++) { 41 | k = 0; 42 | for (int j = 0; j <= 18; j++) { 43 | if (i + j <= n) { 44 | k = k << 1 | g[i + j]; 45 | f[j + 1][k] = 1; 46 | } 47 | else break; 48 | } 49 | } 50 | 51 | for (len = 1; len <= 19; len++) { 52 | for (k = 0; k < (1<= 0; i--) 62 | printf ("%c", k & (1 << i) ? 'a' : 'b'); 63 | } -------------------------------------------------------------------------------- /100-199/143.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 143. Long Live the Queen 3 | 4 | 5 | time limit per test: 0.25 sec. 6 | memory limit per test: 4096 KB 7 | 8 | The Queen of Byteland is very loved by her people. In order to show her their love, the Bytelanders have decided to conquer a new country which will be named according to the queen's name. This new country contains N towns. The towns are connected by bidirectional roads and there is exactly ONE path between any two towns, walking on the country's roads. For each town, the profit it brings to the owner is known. Although the Bytelanders love their queen very much, they don't want to conquer all the N towns for her. They will be satisfied with a non-empty subset of these towns, with the following 2 properties: there exists a path from every town in the subset to every other town in the subset walking only through towns in the subset and the profit of the subset is maximum. The profit of a subset of the N towns is equal to the sum of the profits of the towns which belong to the subset. Your task is to find the maximum profit the Bytelanders may get. 9 | 10 | Input 11 | 12 | The first line of input will contain the number of towns N (1<=N<=16 000). The second line will contain N integers: the profits for each town, from 1 to N. Each profit is an integer number between -1000 and 1000. The next N-1 lines describe the roads: each line contains 2 integer numbers a and b, separated by blanks, denoting two different towns between which there exists a road. 13 | 14 | Output 15 | 16 | The output should contain one integer number: the maximum profit the Bytelanders may get. 17 | 18 | Sample Input 19 | 20 | 5 21 | -1 1 3 1 -1 22 | 4 1 23 | 1 3 24 | 1 2 25 | 4 5 26 | Sample Output 27 | 28 | 4 29 | ************************************************************************/ 30 | #include 31 | #include 32 | #include 33 | #define INf 16010 34 | 35 | using namespace std; 36 | vector g[INf]; 37 | int val[INf], f[INf]; 38 | 39 | int dfs (int x, int fa) { 40 | f[x] = val[x]; 41 | for (int i = 0; i < g[x].size(); i++) { 42 | int temp = 0; 43 | if (g[x][i] != fa) 44 | temp = dfs (g[x][i], x); 45 | if (temp > 0) f[x] += temp; 46 | } 47 | return f[x]; 48 | } 49 | int main() { 50 | int n, x, y; 51 | cin >> n; 52 | for (int i = 1; i <= n; i++) 53 | cin >> val[i]; 54 | for (int i = 1; i < n; i++) { 55 | cin >> x >> y; 56 | g[x].push_back (y); 57 | g[y].push_back (x); 58 | } 59 | 60 | dfs (1, -1); 61 | int ans = INT_MIN; 62 | for (int i = 1; i <= n; i++) 63 | ans = max (ans, f[i]); 64 | 65 | cout << ans; 66 | return 0; 67 | } -------------------------------------------------------------------------------- /100-199/144.cpp: -------------------------------------------------------------------------------- 1 | /*********************************************************** 2 | 144. Meeting 3 | 4 | 5 | time limit per test: 0.25 sec. 6 | memory limit per test: 4096 KB 7 | 8 | Two of the three members of the winning team of one of the ACM regional contests are going to meet in order to train for the upcoming World Finals. They decided that they will meet sometime between X o'clock and Y o'clock. Because they never get anywhere on time (they were late even on the day of the regional contest), they did not set an exact time when they will meet. However, they decided that the one who gets first at the meeting point will not wait more than Z minutes for the other one (they calculated that, if the other one will not come within Z minutes from the arrival of the first of them, then it is very probable that he will not show up at all). 9 | Knowing that, in the end, both of them will show up at some time between X o'clock and Y o'clock (not necessarily after an integer number of minutes), compute which is the probability that they will actually meet. 10 | 11 | Input 12 | 13 | The input will contain 2 integer numbers X and Y (0<=X 27 | #include 28 | using namespace std; 29 | 30 | 31 | int main() { 32 | int a,b; 33 | double v; 34 | cin >> a >> b >> v; 35 | 36 | double total = (b-a)*(b-a)*3600; 37 | double s = (b-a)*60-v; 38 | double f = s*s; 39 | double res = total - f; 40 | res = res/total; 41 | printf("%.7f",res); 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /100-199/146.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 146. The Runner 3 | 4 | time limit per test: 0.25 sec. 5 | memory limit per test: 4096 KB 6 | input: standard input 7 | output: standard output 8 | 9 | 10 | 11 | The runner moves along the ring road with length L. His way consists of N intervals. First he ran T1 minutes with speed V1, then T2 minutes with speed V2 and so on till the N-th interval, where he ran TN minutes with speed VN. Your task is to find the distance from start to finish along the ring road. The distance along the ring road is the length of the shortest way all points of which belongs to the ring road. 12 | 13 | Input 14 | Real number L (1<=L<=1000, with 4 signs after decimal point) and natural number N (N<=20000) are written in the first line. Each of the following N lines contains two integer numbers Ti and Vi (1<=Ti<=10^7, 1<=Vi<=10^6). 15 | 16 | Output 17 | Write the only one real number with 4 digits after decimal points: the distance from start to finish. 18 | 19 | Sample test(s) 20 | 21 | Input 22 | 2 1 23 | 1 3 24 | 25 | Output 26 | 1.0000 27 | ************************************************************************/ 28 | #include 29 | #include 30 | #include 31 | using namespace std; 32 | 33 | int main() { 34 | double len; 35 | int N; 36 | long long res(0); 37 | long long C; 38 | 39 | cin >> len >> N; 40 | C = round(len*10000); 41 | long long t,s; 42 | for(int i = 0;i < N;i++) 43 | { 44 | cin >> s >> t; 45 | res = (res + s*t*10000)%C; 46 | } 47 | 48 | double ans = (res*1.0)/10000; 49 | 50 | if(ans <= len/2) printf("%.4f", ans); 51 | else printf("%.4f", len - ans); 52 | 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /100-199/149.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 149. Computer Network 3 | 4 | time limit per test: 0.25 sec. 5 | memory limit per test: 4096 KB 6 | input: standard input 7 | output: standard output 8 | 9 | 10 | 11 | A school bought the first computer some time ago. During the recent years the school bought N-1 new computers. Each new computer was connected to one of settled earlier. Managers of school are anxious about slow functioning of the net and want to know for each computer number Si - maximum distance, for which i-th computer needs to send signal (i.e. length of cable to the most distant computer). You need to provide this information. 12 | 13 | Input 14 | There is natural number N (N<=10000) in the first line of input, followed by (N-1) lines with descriptions of computers. i-th line contains two natural numbers - number of computer, to which i-th computer is connected and length of cable used for connection. Total length of cable does not exceed 10^9. Numbers in lines of input are separated by a space. 15 | 16 | Output 17 | Write N lines in output file. i-th line must contain number Si for i-th computer (1<=i<=N). 18 | 19 | Sample test(s) 20 | 21 | Input 22 | 3 23 | 1 1 24 | 1 2 25 | 26 | Output 27 | 2 28 | 3 29 | 3 30 | 31 | ************************************************************************/ 32 | #include 33 | #include 34 | #include 35 | using namespace std; 36 | 37 | int N; 38 | const int maxx = 10010; 39 | 40 | struct Edge 41 | { 42 | int p; 43 | int c; 44 | int v; 45 | Edge():p(-1),c(-1),v(-1){} 46 | Edge(int _p, int _c, int _v):p(_p),c(_c),v(_v){} 47 | }; 48 | 49 | Edge edges[maxx]; 50 | vector maps[maxx]; 51 | int plarge[maxx]; 52 | int slarge[maxx]; 53 | int from[maxx]; 54 | int res[maxx]; 55 | 56 | void dfs(int cur, int pathsum) 57 | { 58 | res[cur] = max(plarge[cur], pathsum); 59 | int f = from[cur]; 60 | for(int i = 0;i < maps[cur].size();i++) 61 | { 62 | Edge e = edges[maps[cur][i]]; 63 | int c = e.c; 64 | int v = e.v; 65 | if(f == c) { 66 | dfs(c, max(slarge[cur], pathsum)+v); 67 | } else { 68 | dfs(c, max(plarge[cur], pathsum)+v); 69 | } 70 | } 71 | } 72 | 73 | 74 | int main() { 75 | fill(plarge, plarge+maxx, 0); 76 | fill(slarge, slarge+maxx, 0); 77 | cin >> N; 78 | for(int i = 1;i < N;i++) 79 | { 80 | int p; 81 | int v; 82 | cin >> p >> v; 83 | int c = i+1; 84 | edges[i] = Edge(p, c, v); 85 | maps[p].push_back(i); 86 | } 87 | 88 | for(int i = N;i >= 2;i--) 89 | { 90 | Edge e = edges[i-1]; 91 | int p = e.p; 92 | if(plarge[p] == 0) 93 | { 94 | plarge[p] = plarge[i] + e.v; 95 | from[p] = i; 96 | } else { 97 | if(plarge[p] < plarge[i] + e.v) 98 | { 99 | int temp = plarge[p]; 100 | plarge[p] = plarge[i] + e.v; 101 | from[p] = i; 102 | if(temp > slarge[p]) slarge[p] = temp; 103 | } else if (plarge[p] > plarge[i] + e.v) { 104 | if(plarge[i] + e.v > slarge[p]) 105 | slarge[p] = plarge[i] + e.v; 106 | } else { 107 | slarge[p] = plarge[p]; 108 | } 109 | } 110 | } 111 | 112 | dfs(1,0); 113 | 114 | for(int i = 1;i <= N;i++) 115 | cout << res[i] << endl; 116 | 117 | return 0; 118 | } 119 | -------------------------------------------------------------------------------- /100-199/152.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 152. Making round 3 | 4 | time limit per test: 0.25 sec. 5 | memory limit per test: 4096 KB 6 | input: standard input 7 | output: standard output 8 | 9 | 10 | 11 | Extraordinary things are around us! All citizens of democratic Berland provided election of president and nobody voted "against all candidates". All votes distributed between N candidates. You was charged to write a program to calculate the results of election. You must indicate a part of votes given to each of the candidates. You must write integer numbers, concidering two conditions: 12 | - Total sum of parts must be exactly 100% 13 | - Every part is an integer number and it must be equal to real part, rounded up or down. 14 | 15 | Input 16 | There is a natural number N (1<=N<=10000) written in the first line - amount of candidates. Second line contains sequence of non-negative integer numbers A1, A2,..., AN; Ai is amount of votes given to the i-th candidate (Ai<=10000). Numbers of sequence are separated by one or more spaces. 17 | 18 | Output 19 | Write sequence of sought parts. Separate numbers by a space. If solution does not exist, write "No solution". If there are several solutions write any of them. 20 | 21 | Sample test(s) 22 | 23 | Input 24 | 2 25 | 10 10 26 | 27 | Output 28 | 50 50 29 | ************************************************************************/ 30 | #include 31 | using namespace std; 32 | 33 | 34 | int main() { 35 | int a[10001]; 36 | int N;cin >> N; 37 | int sum(0); 38 | for(int i = 0;i < N;i++) 39 | { 40 | cin >> a[i]; 41 | sum += a[i]; 42 | } 43 | int re(0); 44 | 45 | for(int i = 0;i < N;i++) 46 | { 47 | int temp = a[i] * 100 / sum; 48 | re += a[i] * 100 - temp * sum; 49 | if(re >= sum) 50 | { 51 | re -= sum; 52 | temp++; 53 | } 54 | cout << temp << " "; 55 | } 56 | 57 | return 0; 58 | } -------------------------------------------------------------------------------- /100-199/154.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 154. Factorial 3 | 4 | time limit per test: 0.25 sec. 5 | memory limit per test: 4096 KB 6 | input: standard input 7 | output: standard output 8 | 9 | 10 | 11 | You task is to find minimal natural number N, so that N! contains exactly Q zeroes on the trail in decimal notation. As you know N! = 1*2*...*N. For example, 5! = 120, 120 contains one zero on the trail. 12 | 13 | Input 14 | One number Q written in the input (0<=Q<=10^8). 15 | 16 | Output 17 | Write "No solution", if there is no such number N, and N otherwise. 18 | 19 | Sample test(s) 20 | 21 | Input 22 | 2 23 | 24 | Output 25 | 10 26 | ************************************************************************/ 27 | #include 28 | using namespace std; 29 | 30 | long long trailingZeroes(long long n, long long base, long long mul) { 31 | if(n < 5) return n*5; 32 | else if(n % base == 0 && n/base == 5) return -1; 33 | else if(n <= 5*base) return (n/base)*mul + trailingZeroes(n%base, (base-1)/5, mul/5); 34 | else return trailingZeroes(n, 5*base+1, mul*5); 35 | } 36 | 37 | int main() { 38 | long long n; cin >> n; 39 | long long v = trailingZeroes(n, 1, 5); 40 | if (v == 0) cout << 1; 41 | else if(v % 5 == 0) cout << v; 42 | else cout << "No solution"; 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /100-199/163.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 163. Wise King 3 | 4 | time limit per test: 0.25 sec. 5 | memory limit per test: 65536 KB 6 | input: standard input 7 | output: standard output 8 | 9 | 10 | 11 | Once upon a time in a country far away lived a king and he had a big kingdom. He was a very wise king but he had one weakness - he could count only up to three. 12 | Nevertheless, he did not consider this to be a really great drawback, since he had a lot of wizards who could count up to one hundred (and some of them, people said, even up to one thousand). But one day the grief came to the kingdom as the outnumbering barbarians started to approach from all sides. And the king then had to make the most important decision in his life. He had to choose which of his sons to make generals that he would send to the borders of the country to lead the army. 13 | However, the king knew that though some of his sons were smart, just like he was, some of them were quite stupid and could only lower army spirits with their wrong decisions. More precisely, he knew about each of his sons his mental potential - an integer number ranging from minus three to three (remember, that the king could count only up to three). He also knew that the chance of his army defeating barbarians was proportional to the sum of some powers of mental potentials of those of his sons that he would make generals (the power exponent was a positive integer number, the same for all his sons and not exceeding three either). Thus he had to choose such a combination of his sons to lead the army, that this sum would be maximal possible. 14 | However, the king himself could not make all appropriate calculations since, for example, the second power (the square) of a number not exceeding three could be greater than three, and therefore he asked you, his most intelligent wizard, to solve this problem. 15 | 16 | Input 17 | The first line of the input file contains the number of the sons of the king (integer number less than or equal to one hundred). The second line contains the positive integer number not exceeding three, the exponent in the formula used to calculate the chance of defeating barbarians. The third line contains the list of mental potentials of king's sons - all integer numbers, not greater than three by their absolute value. 18 | 19 | Output 20 | Output the only number - the maximal possible chance of defeating barbarians calculated as the sum described. 21 | 22 | Sample test(s) 23 | 24 | Input 25 | In the first example below the king should choose his first and third sons to be the generals. In this case the chance to defeat barbarians, which is the sum of cubes of mental potentials of these sons, is eight plus one, that is nine. 26 | In the second example sending his son to lead the army causes the sum to be negative, thus he should not do it and the sum would be zero. 27 | 28 | Sample input #1 29 | 3 30 | 3 31 | 2 -1 1 32 | 33 | Sample input #2 34 | 1 35 | 1 36 | -1 37 | 38 | Output 39 | Sample output #1 40 | 9 41 | 42 | Sample output #2 43 | 0 44 | 45 | ************************************************************************/ 46 | #include 47 | #include 48 | using namespace std; 49 | 50 | int main(void) { 51 | int n, m; 52 | cin >> n >> m; 53 | int map[7]; 54 | int i; 55 | for (i = -3; i <= 3; ++i) { 56 | map[i+3] = (int)pow(i, m); 57 | } 58 | int sum = 0, s; 59 | for (i = 0; i < n; ++i) { 60 | cin >> s; 61 | if (map[s+3] > 0) { 62 | sum += map[s+3]; 63 | } 64 | } 65 | cout << sum; 66 | return 0; 67 | } -------------------------------------------------------------------------------- /100-199/168.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 168. Matrix 3 | 4 | time limit per test: 0.5 sec. 5 | memory limit per test: 16000 KB 6 | input: standard 7 | output: standard 8 | 9 | 10 | 11 | You are given N*M matrix A. You are to find such matrix B, that B[i,j]=min{ A[x,y] : (y>=j) and (x>=i+j-y) } 12 | 13 | Input 14 | On the first line of the input there are two integer numbers, N and M (1<=N,M<=1000). Then matrix A follows: next N lines contains M integers each (not greater than 32000 by absolute value). The j-th number on then i-th of this lines is A[i,j]. 15 | 16 | Output 17 | Write matrix B in the same format as matrix A, but without N and M. 18 | 19 | Sample test(s) 20 | 21 | Input 22 | 3 3 23 | 1 2 3 24 | 4 5 6 25 | 7 8 9 26 | 27 | Output 28 | 1 2 3 29 | 2 3 6 30 | 3 6 9 31 | ************************************************************************/ 32 | #include 33 | #include 34 | #include 35 | using namespace std; 36 | 37 | 38 | int main() { 39 | 40 | int n,m; 41 | scanf("%d%d",&n,&m); 42 | int a[1010][1010]; 43 | int b[1010][1010]; 44 | 45 | for(int i = 0;i < n;i++) 46 | for(int j = 0; j < m;j++) 47 | scanf("%d", &a[i][j]); 48 | 49 | for(int k = m+n-2;k >= 0;k--) 50 | { 51 | for(int j = m-1;j >= 0;j--) 52 | { 53 | int i = k - j; 54 | if(i >= n) break; 55 | if(i < 0) continue; 56 | b[i][j] = a[i][j]; 57 | 58 | if(i+1 < n) b[i][j] = min(b[i][j], b[i+1][j]); 59 | if(i >= 1 && j < m-1) b[i][j] = min(b[i][j], b[i-1][j+1]); 60 | if(j+1 < m) b[i][j] = min(b[i][j], b[i][j+1]); 61 | } 62 | } 63 | 64 | for(int i=0;i0) and (n mod P(n)=0). 14 | Let us call n to be a perfect number, if both n and n+1 are good numbers. 15 | 16 | You are to write a program, which, given the number K, counts all such 17 | numbers n that n is perfect and n contains exactly K digits in decimal notation. 18 | 19 | Input 20 | Only one number K (1<=K<=1000000) is written in input. 21 | 22 | Output 23 | Output the total number of perfect k-digit numbers. 24 | 25 | Sample test(s) 26 | 27 | Input 28 | 1 29 | 30 | Output 31 | 8 32 | 33 | ************************************************************************/ 34 | #include 35 | 36 | int main(void) { 37 | int k; 38 | scanf ("%d", &k); 39 | if (k == 1) { 40 | printf ("8\n"); 41 | return 0; 42 | } 43 | int count = 1; 44 | if ((k-1)%3==0) { 45 | count += 2; 46 | if ((k-1)%6==0) { 47 | count++; 48 | } 49 | } 50 | printf ("%d\n", count); 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /100-199/170.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | > File Name: 170.cpp 3 | > Author: Louis1992 4 | > Mail: zhenchaogan@gmail.com 5 | > Blog: http://gzc.github.io 6 | > Created Time: Fri Jul 17 10:13:09 2015 7 | ************************************************************************/ 8 | #include 9 | #include 10 | using namespace std; 11 | 12 | 13 | int main() { 14 | 15 | int a[5000] = {0}; 16 | int b[5000] = {0}; 17 | string s1,s2; 18 | cin >> s1 >> s2; 19 | if(s1.length() != s2.length()) 20 | { 21 | cout << -1; 22 | return 0; 23 | } 24 | 25 | int temp1(0),temp2(0); 26 | for(int i = 0;i < s1.length();i++) 27 | { 28 | if(s1[i] == '-') 29 | a[temp1++] = i; 30 | if(s2[i] == '-') 31 | b[temp2++] = i; 32 | } 33 | 34 | if(temp1 != temp2) 35 | { 36 | cout << -1; 37 | return 0; 38 | } 39 | 40 | int res(0); 41 | for(int i = 0;i < temp1;i++) 42 | res += abs(a[i]-b[i]); 43 | 44 | cout << res; 45 | return 0; 46 | } -------------------------------------------------------------------------------- /100-199/172.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 172. eXam 3 | 4 | time limit per test: 0.25 sec. 5 | memory limit per test: 4096 KB 6 | input: standard 7 | output: standard 8 | 9 | 10 | 11 | In Russia school pupils must do some exams before leaving school. Among others, they must do two "selective" exams. This means that school provides a list of available subjects; each pupil selects two different subjects from this list and is going to do this exams. According to rules, pupil isn't allowed to do both exams at the same day, so the school must schedule the exams, i.e. provide some days when pupils will be able to do exams. 12 | 13 | One school does not want to warn teachers too much. They want to schedule all the exams into two days in such way that exams on some subjects are on the first day, and exams on all other (and only on them) are on second. You are to write a program, which will determine, if it is possible to schedule exams in this way so that all pupils will be able to do all their selected exams. 14 | 15 | Input 16 | On the first line of input there are two integers N and M (1<=N<=200, 1<=M<=30000) - the number of available subjects and the number of pupils. Then M lines follows; on i-th of them there are two integers - the numbers of exams, which were selected by i-th pupil. Exams are numerated from 1 to N. 17 | 18 | Output 19 | If the solution exists, write on the first line of output only one word "yes". On the second line write the total number of exams, which must be held on first day, and on the third line - the numbers of subjects of this exams. If there exist several solutions, output any. If no solution exists, write to output only one word "no". 20 | 21 | Sample test(s) 22 | 23 | Input 24 | 4 4 25 | 1 2 26 | 3 4 27 | 2 4 28 | 1 3 29 | 30 | Output 31 | yes 32 | 2 33 | 1 4 34 | ************************************************************************/ 35 | #include 36 | #include 37 | #include 38 | using namespace std; 39 | 40 | int N,M; 41 | 42 | struct Node{ 43 | int color; 44 | vector edges; 45 | Node():color(0){} 46 | }; 47 | 48 | struct Edge{ 49 | int v1,v2; 50 | bool visited; 51 | Edge(){}; 52 | Edge(int _v1, int _v2, bool _vis){ 53 | v1 = _v1;v2 = _v2;visited = _vis; 54 | } 55 | }; 56 | 57 | struct Edge Edges[30010]; 58 | struct Node nodes[300]; 59 | 60 | bool BFS(int start) 61 | { 62 | queue myqueue; 63 | myqueue.push(start); 64 | 65 | while(!myqueue.empty()) 66 | { 67 | int node1 = myqueue.front(); 68 | myqueue.pop(); 69 | vector edges = nodes[node1].edges; 70 | for(int i = 0;i < edges.size();i++) 71 | { 72 | int e = edges[i]; 73 | if(Edges[e].visited) continue; 74 | Edges[e].visited = true; 75 | int node2 = node1 ^ Edges[e].v1 ^ Edges[e].v2; 76 | int c1 = nodes[node1].color; 77 | int c2 = nodes[node2].color; 78 | if(c2 > 0 && c1 == c2) return false; 79 | if(c2 == 0) 80 | { 81 | nodes[node2].color = 3 - c1; 82 | myqueue.push(node2); 83 | } 84 | 85 | } 86 | } 87 | return true; 88 | } 89 | 90 | 91 | 92 | int main() { 93 | int front,back; 94 | cin >> N >> M; 95 | 96 | int index = 0; 97 | while(index < M) 98 | { 99 | cin >> front >> back; 100 | Edges[index] = Edge(front,back,false); 101 | nodes[front].edges.push_back(index); 102 | nodes[back].edges.push_back(index); 103 | index++; 104 | } 105 | 106 | for(int i = 1;i <= N;i++) 107 | { 108 | if(nodes[i].color == 0) 109 | { 110 | nodes[i].color = 1; 111 | bool fff = BFS(i); 112 | 113 | if(!fff) { 114 | cout << "no"; 115 | return 0; 116 | } 117 | } 118 | } 119 | 120 | 121 | vectorres; 122 | for(int i = 1;i <= N;i++) 123 | if(nodes[i].color != 2) 124 | res.push_back(i); 125 | 126 | cout << "yes" << endl << res.size() << endl; 127 | for(int i = 0;i < res.size();i++) 128 | cout << res[i] << " "; 129 | 130 | 131 | return 0; 132 | } 133 | -------------------------------------------------------------------------------- /100-199/175.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 175. Encoding 3 | 4 | time limit per test: 0.25 sec. 5 | memory limit per test: 4096 KB 6 | input: standard 7 | output: standard 8 | 9 | 10 | 11 | Let phi(W) is the result of encoding for algorithm: 12 | 1. If the length of W is 1 then phi(W) is W; 13 | 2. Let coded word is W = w1w2...wN and K = N / 2 (rounded down); 14 | 3. phi(W) = phi(wNwN-1...wK+1) + phi(wKwK-1...w1). 15 | For example, phi('Ok') = 'kO', phi('abcd') = 'cdab'. 16 | Your task is to find position of letter wq in encoded word phi(W). 17 | 18 | Input 19 | Given integers N, q (1 <= N <= 10^9; 1<= q <= N), where N is the length of word W. 20 | 21 | Output 22 | Write position of letter wq in encoded word phi(W). 23 | 24 | Sample test(s) 25 | 26 | Input 27 | 9 4 28 | 29 | Output 30 | 8 31 | 32 | ************************************************************************/ 33 | #include 34 | using namespace std; 35 | 36 | int help(int N, int p) 37 | { 38 | if(N == 1) return 1; 39 | int k = N/2; 40 | if(p > k) return help(N-k, N-p+1); 41 | else return (N-k) + help(k, k-p+1); 42 | } 43 | 44 | 45 | int main() { 46 | int N,q; cin >> N >> q; 47 | cout << help(N, q); 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /100-199/179.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 179. Brackets light 3 | 4 | time limit per test: 0.25 sec. 5 | memory limit per test: 131072 KB 6 | input: standard 7 | output: standard 8 | 9 | 10 | 11 | There is a correct brackets sequence. It's length doesn't exceed 10000 symbols. 12 | Your task is to find next (in lexicographic order) correct brackets sequence with the same length. You may assume that '(' < ')'. 13 | 14 | Input 15 | The first line of the input contains correct brackets sequence. There are only '(' and ')' symbols in the input. 16 | 17 | Output 18 | Write sought sequence in the single line of the output or 'No solution' if solution doesn't exist. 19 | 20 | Sample test(s) 21 | 22 | Input 23 | (())() 24 | 25 | Output 26 | ()(()) 27 | 28 | ************************************************************************/ 29 | 30 | #include 31 | #include 32 | #include 33 | using namespace std; 34 | 35 | int f[11111], flag; 36 | string s; 37 | 38 | int main() { 39 | cin >> s; 40 | int s1 = 0, s2 = 0, len = s.size() - 1; 41 | 42 | for (int i = 0; i <= len; i++) { 43 | if (s[i] == '(') 44 | f[i] = s1++; 45 | else 46 | f[i] = s2++; 47 | } 48 | 49 | for (int i = len, t; i >= 0; i--) { 50 | if (s[i] == ')') t = i; 51 | else if (f[t] < f[i]) { 52 | swap (s[len], s[i]); 53 | reverse (s.begin() + i + 1, s.end() ); 54 | flag = 1; 55 | break; 56 | } 57 | } 58 | 59 | if (flag == 0) 60 | cout << "No solution"; 61 | else 62 | cout << s; 63 | } -------------------------------------------------------------------------------- /100-199/180.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 180. Inversions 3 | 4 | time limit per test: 0.25 sec. 5 | memory limit per test: 4096 KB 6 | input: standard 7 | output: standard 8 | 9 | 10 | 11 | There are N integers (1<=N<=65537) A1, A2,.. AN (0<=Ai<=10^9). You need to find amount of such pairs (i, j) that 1<=iA[j]. 12 | 13 | Input 14 | The first line of the input contains the number N. The second line contains N numbers A1...AN. 15 | 16 | Output 17 | Write amount of such pairs. 18 | 19 | Sample test(s) 20 | 21 | Input 22 | 5 23 | 2 3 1 5 4 24 | 25 | Output 26 | 3 27 | 28 | ************************************************************************/ 29 | #include 30 | using namespace std; 31 | 32 | const int MAXX = 65540; 33 | int A[MAXX] = {0}; 34 | 35 | long long merge(int A[], int p, int q, int r) { 36 | int i, j, k; 37 | long long inversions = 0; 38 | 39 | int n1 = q - p + 1; 40 | int n2 = r - q; 41 | 42 | int L[n1]; 43 | int R[n2]; 44 | 45 | for (i = 0; i < n1; i++) L[i] = A[p + i]; 46 | for (j = 0; j < n2; j++) R[j] = A[q + j + 1]; 47 | 48 | for(i = 0, j = 0, k = p; k <= r; k++) { 49 | if (i == n1) { 50 | A[k] = R[j++]; 51 | } else if (j == n2) { 52 | A[k] = L[i++]; 53 | } else if (L[i] <= R[j]) { 54 | A[k] = L[i++]; 55 | } else { 56 | A[k] = R[j++]; 57 | inversions += n1 - i; 58 | } 59 | } 60 | 61 | return inversions; 62 | } 63 | 64 | long long merge_sort(int A[], int p, int r) { 65 | if (p < r) { 66 | long long inversions = 0; 67 | int q = (p + r) / 2; 68 | inversions += merge_sort(A, p, q); 69 | inversions += merge_sort(A, q + 1, r); 70 | inversions += merge(A, p, q, r); 71 | return inversions; 72 | } else { 73 | return 0; 74 | } 75 | } 76 | 77 | int main() 78 | { 79 | int N;cin >> N; 80 | for(int i = 0;i < N;i++) 81 | cin >> A[i]; 82 | cout << merge_sort(A, 0, N-1); 83 | return 0; 84 | } -------------------------------------------------------------------------------- /100-199/181.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 181. X-Sequence 3 | 4 | time limit per test: 0.25 sec. 5 | memory limit per test: 4096 KB 6 | input: standard 7 | output: standard 8 | 9 | 10 | 11 | Let {xi} be the infinite sequence of integers: 12 | 1) x0 = A; 13 | 2) xi = (alpha * xi-1^2 + beta * xi-1 + gamma) mod M, for i >= 1. 14 | Your task is to find xk if you know A, alpha, beta, gamma, M and k. 15 | 16 | Input 17 | Given A (1 <= A <= 10000), alpha (0 <= alpha <= 100), beta (0 <= beta <= 100), gamma (0 <= gamma <= 100), M (1 <= M <= 1000), k (0 <= k <= 10^9). All numbers are integer. 18 | 19 | Output 20 | Write xk. 21 | 22 | Sample test(s) 23 | 24 | Input 25 | 1 1 1 1 10 1 26 | 27 | Output 28 | 3 29 | 30 | ************************************************************************/ 31 | #include 32 | #include 33 | using namespace std; 34 | 35 | const int MAXX = 1010; 36 | bool flag[MAXX]; 37 | int ans[MAXX]; 38 | 39 | long long A, alpha, beta, gamma, M, k; 40 | 41 | inline long long get (long long x) { 42 | return (alpha * x * x + beta * x + gamma) % M; 43 | } 44 | 45 | 46 | int main() { 47 | 48 | cin >> A >> alpha >> beta >> gamma >> M >> k; 49 | fill(flag, flag+MAXX, false); 50 | 51 | if(k == 0) 52 | { 53 | cout << A; 54 | return 0; 55 | } 56 | 57 | int t = 0; 58 | int x = get(A); 59 | while(!flag[x]) 60 | { 61 | flag[x] = true; 62 | t++; 63 | ans[t] = x; 64 | x = get(x); 65 | } 66 | 67 | int i = 1; 68 | for(;i <= t;i++) 69 | if(ans[i] == x) 70 | break; 71 | 72 | int loop = t - i + 1; 73 | int d = t - loop; 74 | if(k <= t) cout << ans[k]; 75 | else cout << ans[(1+(k - d - 1) % loop) + d]; 76 | return 0; 77 | } 78 | -------------------------------------------------------------------------------- /100-199/184.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 184. Patties 3 | 4 | time limit per test: 0.25 sec. 5 | memory limit per test: 4096 KB 6 | input: standard input 7 | output: standard output 8 | 9 | 10 | 11 | Petya is well-known with his famous cabbage patties. Petya's birthday will come very soon, and he wants to invite as many guests as possible. But the boy wants everybody to try his specialty of the house. That's why he needs to know the number of the patties he can cook using the stocked ingredients. Petya has P grams of flour, M milliliters of milk and C grams of cabbage. He has plenty of other ingredients. Petya knows that he needs K grams of flour, R milliliters of milk and V grams of cabbage to cook one patty. Please, help Petya calculate the maximum number of patties he can cook. 12 | 13 | Input 14 | The input file contains integer numbers P, M, C, K, R and V, separated by spaces and/or line breaks (1 <= P, M, C, K, R, V <= 10000). 15 | 16 | Output 17 | Output the maximum number of patties Petya can cook. 18 | 19 | Sample test(s) 20 | 21 | Input 22 | 3000 1000 500 23 | 30 15 60 24 | 25 | Output 26 | 8 27 | **************************************************************************/ 28 | 29 | #include 30 | #include 31 | 32 | using namespace std; 33 | 34 | int main() 35 | { 36 | int P, M, C, K, R, V; 37 | cin >> P >> M >> C >> K >> R >> V; 38 | 39 | int a = P/K; 40 | int b = M/R; 41 | int c = C/V; 42 | 43 | int maximum = 0; 44 | maximum = min(a, b); 45 | maximum = min(maximum, c); 46 | 47 | cout << maximum; 48 | 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /100-199/186.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 186. The Chain 3 | 4 | time limit per test: 0.25 sec. 5 | memory limit per test: 4096 KB 6 | input: standard input 7 | output: standard output 8 | 9 | 10 | 11 | Smith has N chains. Each chain is the sequence of successively connected links. The length of each chain is known: the first chain contains L1 links, the second - L2, ..., the last one - LN. 12 | He can make a following series of actions in a minute: 13 | 1. to unchain one link 14 | 2. to remove or to put into the unchained link some other links of any chain 15 | 3. to chain the link 16 | Your task is to determine the minimum time which will take the smith to connect all the chains in one line, i.e. the chain will look like a chain made up of successively connected links. 17 | 18 | Input 19 | The first line contains natural number N<=100. The second line contains L1, L2, ..., LN (1<=Li<=100, for all i = 1..N). 20 | 21 | Output 22 | Output the only integer number - the solution to the problem. 23 | 24 | Sample test(s) 25 | 26 | Input 27 | 2 28 | 3 4 29 | 30 | Output 31 | 1 32 | ************************************************************************/ 33 | #include 34 | #include 35 | using namespace std; 36 | int a[110], n, l, r, ans; 37 | int main() 38 | { 39 | cin >> n; 40 | for (int i = 0; i < n; i++) 41 | cin >> a[i]; 42 | r = n - 1; 43 | sort (a, a + n); 44 | while (l < r) { 45 | a[l]--, r--; 46 | if (!a[l]) l++; 47 | ans++; 48 | } 49 | cout << ans; 50 | return 0; 51 | } -------------------------------------------------------------------------------- /100-199/193.java: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 193. Chinese Girls' Amusement 3 | time limit per test: 0.25 sec. 4 | memory limit per test: 65536 KB 5 | input: standard 6 | output: standard 7 | 8 | 9 | You must have heard that the Chinese culture is quite different from that of Europe or Russia. So some Chinese habits seem quite unusual or even weird to us. 10 | So it is known that there is one popular game of Chinese girls. N girls stand forming a circle and throw a ball to each other. First girl holding a ball throws it to the K-th girl on her left (1 ≤ K ≤ N/2). That girl catches the ball and in turn throws it to the K-th girl on her left, and so on. So the ball is passed from one girl to another until it comes back to the first girl. If for example N = 7 and K = 3, the girls receive the ball in the following order: 1, 4, 7, 3, 6, 2, 5, 1. 11 | 12 | To make the game even more interesting the girls want to choose K as large as possible, but they want one condition to hold: each girl must own the ball during the game. 13 | 14 | Input 15 | Input file contains one integer number N (3 ≤ N ≤ 102000) - the number of Chinese girls taking part in the game. 16 | Output 17 | Output the only number - K that they should choose. 18 | Sample test(s) 19 | Input 20 | Test #1 21 | 7 22 | Test #2 23 | 6 24 | 25 | Output 26 | Test #1 27 | 3 28 | Test #2 29 | 1 30 | ************************************************************************/ 31 | import java.util.*; 32 | import java.math.*; 33 | 34 | public class Solution 35 | { 36 | public static void main(String []arg){ 37 | Scanner cin = new Scanner(System.in); 38 | BigInteger n = cin.nextBigInteger(); 39 | if(n.mod(BigInteger.valueOf(2)).equals(BigInteger.ONE)){ 40 | System.out.println(n.divide(BigInteger.valueOf(2))); 41 | } 42 | else { 43 | BigInteger n2 = n.divide(BigInteger.valueOf(2)); 44 | n2 = n2.subtract(BigInteger.ONE); 45 | if(n2.mod(BigInteger.valueOf(2)).equals(BigInteger.ZERO)) 46 | n2 = n2.subtract(BigInteger.ONE); 47 | System.out.println(n2); 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /100-199/196.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 196. Matrix Multiplication 3 | 4 | time limit per test: 0.25 sec. 5 | memory limit per test: 65536 KB 6 | input: standard 7 | output: standard 8 | 9 | 10 | 11 | Let us consider an undirected graph G = which has N vertices and M edges. Incidence matrix of this graph is an N × M matrix A = {aij}, such that aij is 1 if i-th vertex is one of the ends of j-th edge and 0 in the other case. Your task is to find the sum of all elements of the matrix ATA where AT is A transposed, i.e. an M × N matrix obtained from A by turning its columns to rows and vice versa. 12 | 13 | Input 14 | 15 | The first line of the input file contains two integer numbers — N and M (2 le N le 10,000, 1 le M le 100,000). 2M integer numbers follow, forming M pairs, each pair describes one edge of the graph. All edges are different and there are no loops (i.e. edge ends are distinct). 16 | 17 | Output 18 | 19 | Output the only number — the sum requested. 20 | 21 | Sample test(s) 22 | 23 | Input 24 | 4 4 25 | 1 2 26 | 1 3 27 | 2 3 28 | 2 4 29 | 30 | Output 31 | 18 32 | ************************************************************************/ 33 | #include 34 | int sum[10009], n, m, x, y; 35 | int main() { 36 | scanf ("%d %d", &n, &m); 37 | for (int i = 1; i <= m; i++) { 38 | scanf ("%d %d", &x, &y); 39 | sum[x]++, sum[y]++; 40 | } 41 | int ans = 0; 42 | for (int i = 1; i <= n; i++) 43 | ans += sum[i] * sum[i]; 44 | printf ("%d", ans); 45 | return 0; 46 | } -------------------------------------------------------------------------------- /100-199/199.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | 3 | 199. Beautiful People 4 | 5 | time limit per test: 0.25 sec. 6 | memory limit per test: 65536 KB 7 | input: standard 8 | output: standard 9 | 10 | 11 | 12 | The most prestigious sports club in one city has exactly N members. Each of its members is strong and beautiful. More precisely, i-th member of this club (members being numbered by the time they entered the club) has strength Si and beauty Bi . Since this is a very prestigious club, its members are very rich and therefore extraordinary people, so they often extremely hate each other. Strictly speaking, i-th member of the club Mr X hates j-th member of the club Mr Y if Si ≤ Sj and Bi ≥ Bj or if Si ≥ Sj and Bi ≤ Bj (if both properties of Mr X are greater then corresponding properties of Mr Y, he doesn't even notice him, on the other hand, if both of his properties are less, he respects Mr Y very much). 13 | 14 | To celebrate a new 2003 year, the administration of the club is planning to organize a party. However they are afraid that if two people who hate each other would simultaneouly attend the party, after a drink or two they would start a fight. So no two people who hate each other should be invited. On the other hand, to keep the club presti≥ at the apropriate level, administration wants to invite as many people as possible. 15 | 16 | Being the only one among administration who is not afraid of touching a computer, you are to write a program which would find out whom to invite to the party. 17 | 18 | Input 19 | 20 | The first line of the input file contains integer N — the number of members of the club. ( 2 ≤ N ≤ 100,000 ). Next N lines contain two numbers each — Si and Bi respectively ( 1 ≤ Si, Bi ≤ 109 ). 21 | 22 | Output 23 | 24 | On the first line of the output file print the maximum number of the people that can be invited to the party. On the second line output N integers — numbers of members to be invited in arbitrary order. If several solutions exist, output any one. 25 | 26 | Sample test(s) 27 | 28 | Input 29 | 30 | 4 31 | 1 1 32 | 1 2 33 | 2 1 34 | 2 2 35 | 36 | Output 37 | 38 | 2 39 | 1 4 40 | 41 | *****************************************************************/ 42 | 43 | #include 44 | #include 45 | #include 46 | using namespace std; 47 | 48 | struct node { 49 | int first, second, id; 50 | }; 51 | 52 | struct node a[100009]; 53 | int c[100009]; 54 | int pre[100009] = {-1}; 55 | 56 | bool cmp (node a, node b) { 57 | if (a.first == b.first) return a.second > b.second; 58 | return a.first < b.first; 59 | } 60 | 61 | int find(int len, int i) 62 | { 63 | int left(1),right(len),mid = (left+right)/2; 64 | while(left <= right) 65 | { 66 | if (a[i].second > a[c[mid]].second) 67 | { 68 | left = mid + 1; 69 | } 70 | else 71 | right = mid - 1; 72 | mid = (left + right)/2; 73 | } 74 | return left; 75 | } 76 | 77 | int main() 78 | { 79 | int n, i, j, len; 80 | scanf("%d", &n); 81 | for (int i = 1; i <= n; i++) { 82 | scanf("%d%d",&a[i].first,&a[i].second); 83 | a[i].id = i; 84 | } 85 | sort (a + 1, a + 1 + n, cmp); 86 | 87 | c[1] = 1; 88 | len = 1; 89 | 90 | for(i = 2;i <= n;i++) 91 | { 92 | j = find(len, i); 93 | c[j] = i; 94 | if(j > 1) 95 | pre[a[i].id] = a[c[j-1]].id; 96 | if(j > len) 97 | len = j; 98 | } 99 | 100 | printf("%d\n",len); 101 | 102 | for(int i = a[c[len]].id; i > 0;i = pre[i]) 103 | printf("%d ",i); 104 | return 0; 105 | } -------------------------------------------------------------------------------- /100-199/README.md: -------------------------------------------------------------------------------- 1 | # Order : group by acceptance 2 | 3 | * Over 5000 : 100 102 105 123 4 | * [3000,5000) : 101 104 107 112 113 115 117 127 135 184 5 | * [2000,3000) : 108 114 116 118 126 130 133 144 154 175 6 | * [1800,2000) : 106 111 134 180 181 7 | * [1700,1800) : 103 109 143 169 170 172 8 | * [1600,1700) : 124 152 163 9 | * [1500,1600) : 146 149 168 196 10 | * [1300,1500) : 119 125 131 139 179 11 | * [1200,1300) : 120 142 186 12 | -------------------------------------------------------------------------------- /200-299/222.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 222. Little Rooks 3 | 4 | time limit per test: 0.25 sec. 5 | memory limit per test: 65536 KB 6 | input: standard 7 | output: standard 8 | 9 | 10 | Inspired by a "Little Bishops" problem, Petya now wants to solve problem for rooks. 11 | 12 | A rook is a piece used in the game of chess which is played on a board of square grids. A rook can only move horizontally and vertically from its current position and two rooks attack each other if one is on the path of the other. 13 | 14 | Given two numbers n and k, your job is to determine the number of ways one can put k rooks on an n × n chessboard so that no two of them are in attacking positions. 15 | 16 | Input 17 | 18 | The input file contains two integers n (1 ≤ n ≤ 10) and k (0 ≤ k ≤ n2). 19 | 20 | Output 21 | 22 | Print a line containing the total number of ways one can put the given number of rooks on a chessboard of the given size so that no two of them are in attacking positions. 23 | 24 | Sample test(s) 25 | 26 | Input 27 | 4 4 28 | 29 | Output 30 | 24 31 | ************************************************************************/ 32 | #include 33 | using namespace std; 34 | 35 | long long mul(int start, int end) 36 | { 37 | long long res(1); 38 | while(start <= end) 39 | { 40 | res *= start; 41 | start++; 42 | } 43 | return res; 44 | } 45 | 46 | int main() 47 | { 48 | int n,k; 49 | cin >> n >> k; 50 | 51 | if(k > n) 52 | { 53 | cout << 0; 54 | return 0; 55 | } 56 | 57 | long long res = mul(n-k+1, n); 58 | res /= mul(1, k); 59 | res *= mul(n-k+1,n); 60 | cout << res << endl; 61 | 62 | return 0; 63 | } -------------------------------------------------------------------------------- /200-299/223.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 223. Little Kings 3 | 4 | time limit per test: 0.5 sec. 5 | memory limit per test: 65536 KB 6 | input: standard 7 | output: standard 8 | 9 | 10 | 11 | After solving nice problems about bishops and rooks, Petya decided that he would like to learn to play chess. He started to learn the rules and found out that the most important piece in the game is the king. 12 | 13 | The king can move to any adjacent cell (there are up to eight such cells). Thus, two kings are in the attacking position, if they are located on the adjacent cells. 14 | 15 | Of course, the first thing Petya wants to know is the number of ways one can position k kings on a chessboard of size n × n so that no two of them are in the attacking position. Help him! 16 | 17 | Input 18 | 19 | The input file contains two integers n (1 ≤ n ≤ 10) and k (0 ≤ k ≤ n2). 20 | 21 | Output 22 | 23 | Print a line containing the total number of ways one can put the given number of kings on a chessboard of the given size so that no two of them are in attacking positions. 24 | 25 | Sample test(s) 26 | 27 | Input 28 | Test #1 29 | 30 | 3 2 31 | 32 | Test #2 33 | 34 | 4 4 35 | 36 | Output 37 | Test #1 38 | 39 | 16 40 | 41 | Test #2 42 | 43 | 79 44 | ************************************************************************/ 45 | #include 46 | #include 47 | #include 48 | using namespace std; 49 | const int MAXM=520; 50 | int n,k; 51 | int s[MAXM];//状态数 52 | int c[MAXM];//1的个数 53 | long long f[13][MAXM][103]; 54 | int ck; 55 | void dfs(int x,int val,int cnt)//DFS寻找每行的状态数 56 | { 57 | if(x==n) 58 | { 59 | s[++ck]=val; 60 | c[ck]=cnt; 61 | return; 62 | } 63 | dfs(x+1,val<<1,cnt); 64 | if(!(val&1)) 65 | dfs(x+1,val<<1|1,cnt+1); 66 | } 67 | bool cont(int s1,int s2)//判断与题意是否矛盾 68 | { 69 | if(s1&s2) return false;//和正上方判断 70 | if(s1&(s2<<1))return false;//和右上方判断 71 | if(s1&(s2>>1))return false;//和左上方判断 72 | return true; 73 | } 74 | void dp() 75 | { 76 | //初始化状态 77 | memset(f,0,sizeof(f)); 78 | f[0][1][0]=1; 79 | //dp 80 | for(int i=1;i<=n;i++) 81 | { 82 | for(int j=1;j<=ck;j++) 83 | { 84 | for(int g=1;g<=ck;g++) 85 | { 86 | for(int p=0;p<=k;p++) 87 | { 88 | if((p >= c[j]) && cont(s[j],s[g])) 89 | f[i][j][p]+=f[i-1][g][p-c[j]]; 90 | } 91 | } 92 | } 93 | } 94 | } 95 | 96 | int main() 97 | { 98 | while(scanf("%d %d",&n,&k)!=EOF) 99 | { 100 | ck=0; 101 | dfs(0,0,0); 102 | dp(); 103 | long long ans=0; 104 | 105 | for(int i=1;i<=ck;++i) 106 | { 107 | ans+=f[n][i][k]; 108 | } 109 | 110 | cout << ans << endl; 111 | 112 | } 113 | 114 | 115 | return 0; 116 | } -------------------------------------------------------------------------------- /200-299/224.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 224. Little Queens 3 | 4 | time limit per test: 0.75 sec. 5 | memory limit per test: 65536 KB 6 | input: standard 7 | output: standard 8 | 9 | 10 | 11 | Well, you might have heard about a curious boy Petya who likes to learn the number of ways one can put k identical chess pieces on a chessboard of size n× n so that no two of them are in the attacking positions. He have solved the problems for bishops, rooks and kings. Recently he has met Farmer John and told him about that. 12 | 13 | Impressed FJ has decided to teach his cows to play chess. The first question Bessie asked on the first lesson was: "What about the number of ways one can put k queens on a chessboard of size n × n, so that no two of them are in the attacking positions?" 14 | 15 | The queen can move diagonally, horizonatally and vertically, thus combining the properties of a bishop and a rook. Two queens are in the attacking positions if they are on the path of each other. 16 | 17 | Input 18 | 19 | The input file contains two integers n (1 ≤ n ≤ 10) and k (0 ≤ k ≤ n2). 20 | 21 | Output 22 | 23 | Print a line containing the total number of ways one can put the given number of queens on a chessboard of the given size so that no two of them are in attacking positions. 24 | ************************************************************************/ 25 | #include 26 | #include 27 | using namespace std; 28 | 29 | int n, sum, max, k, m; 30 | void dfs (int line , int row, int l, int r, int k) { 31 | int pos, p, i; 32 | if (line > n){ 33 | if(k == m) sum++; 34 | return; 35 | } 36 | dfs (line + 1, row, l>>1, r<<1, k); 37 | if (row != max) { 38 | pos = max & (~ (row | l | r) ); 39 | while (pos != 0) { 40 | p = pos & -pos; 41 | pos = pos - p; 42 | dfs (line+1,row | p, (l | p) >> 1, (r | p) << 1, k + 1); 43 | } 44 | } 45 | } 46 | int main() { 47 | scanf ("%d %d", &n, &m); 48 | max = (1 << n) - 1; 49 | dfs (1, 0, 0, 0, 0); 50 | printf ("%d", sum); 51 | } -------------------------------------------------------------------------------- /200-299/226.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 226. Colored graph 3 | 4 | time limit per test: 0.25 sec. 5 | memory limit per test: 4096 KB 6 | input: standard 7 | output: standard 8 | 9 | 10 | 11 | You are given an oriented graph. Each edge of the graph is colored in one of the three colors. Your task is to find the length of the shortest path from the first vertex to the N-th. Note that any two successive edges in the path can't have the same color. 12 | 13 | Input 14 | The first line of the input file consists of two integers N and M (2 <= N <= 200; 0 <= M <= N*N). Next M lines contain descriptions of the edges. Each edge description is a list of three integers X, Y, C (1 <= X, Y <= N, 1 <= C <= 3), where X is the starting vertex of the edge, Y is the finishing vertex and C is the color of the edge. 15 | 16 | Output 17 | Output the length of the shortest path between the first and the N-th vertexes. Output "-1" if the path doesn't exist. 18 | ************************************************************************/ 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | using namespace std; 25 | 26 | int dis[210][4]; 27 | int N,M; 28 | 29 | struct Edge 30 | { 31 | int from; 32 | int to; 33 | int color; 34 | Edge(int f, int t, int c):from(f),to(t),color(c){} 35 | Edge():from(-1),to(-1),color(-1){} 36 | }; 37 | 38 | Edge edges[40010]; 39 | vector E[210]; 40 | 41 | int main() { 42 | for(int i = 0;i < 210;i++) 43 | for(int j = 0;j < 4;j++) 44 | dis[i][j] = 9999999; 45 | dis[1][1] = dis[1][2] = dis[1][3] = 0; 46 | scanf("%d%d", &N, &M); 47 | for(int i = 1;i <= M;i++) 48 | { 49 | scanf("%d%d%d", &edges[i].from, &edges[i].to, &edges[i].color); 50 | E[edges[i].from].push_back(i); 51 | } 52 | 53 | queue myqueue; 54 | bool vis[210] = {false}; 55 | int c[210] = {0}; 56 | myqueue.push(1); 57 | vis[1] = true; 58 | c[1] = 1; 59 | 60 | //顶点入队vis要做标记,另外要统计顶点的入队次数 61 | int OK = 1; 62 | while(!myqueue.empty()) 63 | { 64 | int x; 65 | x = myqueue.front(); myqueue.pop(); vis[x] = false; 66 | //队头元素出队,并且消除标记 67 | vector v = E[x]; 68 | for(int i = 0;i < v.size();i++) //遍历顶点x的邻接节点 69 | { 70 | int edgeindex = v[i]; 71 | Edge e = edges[edgeindex]; 72 | int y = e.to; 73 | int color = e.color; 74 | 75 | //printf("%d, %d, %d\n", x ,y ,color); 76 | 77 | int choosed; 78 | if(color == 1 && dis[x][2] <= dis[x][3]) choosed = 2; 79 | else if(color == 1 && dis[x][2] > dis[x][3]) choosed = 3; 80 | else if(color == 2 && dis[x][1] <= dis[x][3]) choosed = 1; 81 | else if(color == 2 && dis[x][1] > dis[x][3]) choosed = 3; 82 | else if(color == 3 && dis[x][1] <= dis[x][2]) choosed = 1; 83 | else choosed = 2; 84 | 85 | 86 | if( dis[x][choosed]+ 1 < dis[y][color]) 87 | { 88 | dis[y][color] = dis[x][choosed]+ 1; //松弛 89 | if(!vis[y]) //顶点y不在队内 90 | { 91 | vis[y]=1; //标记 92 | c[y]++; //统计次数 93 | myqueue.push(y); //入队 94 | if(c[y] > 100) //超过入队次数上限,说明有负环 95 | { 96 | printf("-1\n"); 97 | return 0; 98 | } 99 | 100 | } 101 | } 102 | 103 | } 104 | } 105 | 106 | int distance = min(dis[N][1], min(dis[N][2], dis[N][3])); 107 | if(distance < 9999999) 108 | printf("%d\n",distance); 109 | else 110 | printf("-1\n"); 111 | 112 | return 0; 113 | } 114 | -------------------------------------------------------------------------------- /200-299/231.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 231. Prime Sum 3 | 4 | time limit per test: 0.25 sec. 5 | memory limit per test: 4096 KB 6 | input: standard 7 | output: standard 8 | 9 | 10 | 11 | Find all pairs of prime numbers (A, B) such that A<=B and their sum is also a prime number and does not exceed N. 12 | 13 | Input 14 | The input of the problem consists of the only integer N (1<=N<=10^6). 15 | 16 | Output 17 | On the first line of the output file write the number of pairs meeting the requirements. Then output all pairs one per line (two primes separated by a space). 18 | 19 | Sample test(s) 20 | 21 | Input 22 | 4 23 | 24 | Output 25 | 0 26 | 27 | ************************************************************************/ 28 | #include 29 | #include 30 | using namespace std; 31 | 32 | int main() { 33 | int n; 34 | cin >> n; 35 | 36 | double c = sqrt(n); 37 | bool *bv = new bool[n]; 38 | for(int i = 3; i <= c; i += 2) 39 | if (!bv[i]) 40 | for(int j = i*i, k = i << 1; j <= n; j += k) 41 | bv[j] = 1; 42 | 43 | int out[10000]; 44 | int num = 0; 45 | for(int i = 3; i <= n-2; i += 2) 46 | if(!bv[i] && !bv[i+2]) 47 | out[num++] = i; 48 | 49 | cout << num << endl; 50 | for(int i = 0;i < num;i++) 51 | cout << 2 << " " << out[i] << endl; 52 | 53 | return 0; 54 | } -------------------------------------------------------------------------------- /200-299/259.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 259. Printed PR 3 | 4 | time limit per test: 0.25 sec. 5 | memory limit per test: 65536 KB 6 | input: standard 7 | output: standard 8 | 9 | 10 | 11 | Small PR-agency got an order to print a very big lot of agitational materials. Agency should print and deliver N leaflets. Agency is very small and has only one printer, but it can print any leaflet. Leaflets can be different, so it is possible that times of printing of leaflets will differ. To print i-th leaflet the printer needs Ti minutes. When leaflet is printed, it should be immediately delivered to its addressee. The agency has unlimited number of couriers, so the courier gets the leaflet as soon as it printed and goes to the addressee. It takes Li minutes to deliver i-th leaflet. You were hired by agency to calculate the minimal time required to finish the job (this is an interval of time from the beginning of printing to the moment when the last leaflet is delivered), considering that the leaflets can be printed in any order. 12 | 13 | Input 14 | The first line contains a number of leaflets - integer number N (1 <= N <= 100). The second line contains N integer numbers Ti (1 <= i <= N). Third line contains N integer numbers Li (1 <= i <= N). You can assume that 1 <= Ti, Li <= 1000. 15 | 16 | Output 17 | You should output only one number - the answer for the problem. 18 | 19 | Sample test(s) 20 | 21 | Input 22 | 2 23 | 2 1 24 | 2 1 25 | 26 | Output 27 | 4 28 | 29 | ************************************************************************/ 30 | #include 31 | #include 32 | #include 33 | 34 | using namespace std; 35 | 36 | struct node{ 37 | int t,l; 38 | node(){} 39 | node(int tt, int ll):t(tt),l(ll){} 40 | bool operator < (const node & rhs) const{ 41 | return l > rhs.l; 42 | } 43 | } ev[110]; 44 | 45 | int main(void) 46 | { 47 | int N; 48 | cin >> N; 49 | for(int i = 0; i < N; ++i) 50 | cin >> ev[i].t; 51 | for(int i = 0; i < N; ++i) 52 | cin >> ev[i].l; 53 | sort(ev,ev+N); 54 | 55 | int ans = 0,cur = 0; 56 | for(int i = 0; i < N; ++i){ 57 | cur += ev[i].t; 58 | ans = max(ans,cur + ev[i].l); 59 | } 60 | cout << ans; 61 | return 0; 62 | } -------------------------------------------------------------------------------- /200-299/276.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 276. Andrew's Troubles 3 | 4 | time limit per test: 0.25 sec. 5 | memory limit per test: 65536 KB 6 | input: standard 7 | output: standard 8 | 9 | 10 | 11 | Famous Berland ACM-ICPC team Anisovka consists of three programmers: Andrew, Michael and Ilya. A long time ago, during the first few months the team was founded, Andrew was very often late to the trainings and contests. To stimulate Andrew to be more punctual, Ilya and Andrew decided to introduce a new rule for team participants. If somebody is late (i.e. comes at least one second after appointed time) he owes a cup of tea to other team members. If he is late for 5 minutes, he owes two cups of tea. If he is late for 15 minutes, he owes three cups of tea. And if he is late for 30 minutes or more, he owes 4 cups of tea. 12 | The training starts at the time S (counted in seconds, from some predefined moment of time) and Andrew comes at the time P (also in seconds, counted from the same moment of time). 13 | Your task is to find how many cups of tea Andrew owes. 14 | 15 | Input 16 | The input file contains single line with integer numbers S and P (0 <= S,P <= 10^4). 17 | 18 | Output 19 | Write to the output file the number of cups Andrew owes. 20 | 21 | Sample test(s) 22 | 23 | Input 24 | Test #1 25 | 10 10 26 | 27 | Test #2 28 | 10 11 29 | 30 | Test #3 31 | 0 300 32 | 33 | Output 34 | Test #1 35 | 0 36 | 37 | Test #2 38 | 1 39 | 40 | Test #3 41 | 2 42 | [submit] 43 | ************************************************************************/ 44 | #include 45 | using namespace std; 46 | int main() 47 | { 48 | int m,n; 49 | scanf("%d %d",&m,&n); 50 | if(m==n) 51 | printf("0\n"); 52 | if(n-m>=1800) 53 | { 54 | printf("4\n"); 55 | return 0; 56 | } 57 | if(n-m>=900) 58 | { 59 | printf("3\n"); 60 | return 0; 61 | } 62 | if(n-m>=300) 63 | { 64 | printf("2\n"); 65 | return 0; 66 | } 67 | if(n>m) 68 | { 69 | printf("1\n"); 70 | return 0; 71 | } 72 | return 0; 73 | } -------------------------------------------------------------------------------- /200-299/296.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 296. Sasha vs. Kate 3 | 4 | Time limit per test: 0.5 second(s) 5 | Memory limit: 65536 kilobytes 6 | input: standard 7 | output: standard 8 | 9 | 10 | 11 | During the regular Mars's World Finals Subregional Programming Contest a boy Sasha lost N "Mars" bars of chocolate to a girl Kate. But for two years already Sasha does not hurry to pay his debt. And now Sasha and Kate decided that Sasha will give Kate P chocolate bars, where number P can be obtained from the number N by removing exactly K decimal digits. Sasha generously let Kate to choose digits to be removed. Your task is to find out how many bars Sasha will give Kate. Of course Kate will choose K digits from the number N in such a way that the resulting number P would be maximal. 12 | 13 | Input 14 | The first line of the input file contains two integer numbers N and K (1≤ N≤ 101000; 0≤ K≤ 999). Number K is strictly less than the number of digits in N. N will not have any leading zeros. 15 | 16 | Output 17 | Output the unknown P. 18 | ************************************************************************/ 19 | #include 20 | #include 21 | 22 | int main() 23 | { 24 | char s[1100]; 25 | int k; 26 | scanf("%s",s); 27 | scanf("%d",&k); 28 | int len=strlen(s); 29 | while(k) 30 | { 31 | int flag=1; 32 | for(int i=1;i 21 | 22 | int main() { 23 | int n, m; 24 | scanf ("%d%d", &n, &m); 25 | int i, tmp, sum = 0; 26 | for (i = 0; i < m; ++i) { 27 | scanf ("%d", &tmp); 28 | sum += tmp; 29 | } 30 | printf ("%d\n", sum%n); 31 | return 0; 32 | } -------------------------------------------------------------------------------- /300-399/302.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 302. BHTML 1.0 3 | 4 | Time limit per test: 0.25 second(s) 5 | Memory limit: 65536 kilobytes 6 | input: standard 7 | output: standard 8 | 9 | 10 | 11 | The hypertext markup language BHTML 1.0 has only two paired tags. They are UP /UP and DOWN /DOWN. The UP /UP tag capitalizes all letters inside its body (between an open tag and a close one), and DOWN /DOWN makes all inside the body letters lowercase. You are given the text consisting of latin letters and tags. Your task is to write the text right as it will be shown in the Bernet Explorer browser window. Tags in the text are arranged correctly, i.e. they form correct bracket sequence. If a letter lays inside several tags, its case is defined by the most inner tag. 12 | 13 | Input 14 | The input contains the string S with the text. The length of the string is a natural number not exceeding 1000. Tags are always written in uppercase. 15 | 16 | Output 17 | Write to the output text after the processing. 18 | 19 | ************************************************************************/ 20 | #include 21 | #include 22 | #include 23 | #include 24 | using namespace std; 25 | 26 | int main () 27 | { 28 | string s1, s2; 29 | stack mystack; 30 | while(cin>>s1) 31 | { 32 | s2.clear(); 33 | for(int i = 0; i < s1.length(); i++) 34 | { 35 | if(s1[i] == '<' && s1[i+1] == 'U'){mystack.push(1); i+=3;} 36 | else if(s1[i] == '<' && s1[i+1] == 'D'){mystack.push(-1); i+=5;} 37 | else if(s1[i] == '<' && s1[i+1] == '/'){mystack.pop(); i+=(s1[i+2] == 'U'?4:6);} 38 | else 39 | { 40 | if(mystack.empty()) 41 | s2 += s1[i]; 42 | else if(mystack.top() == 1) 43 | s2 += toupper(s1[i]); 44 | else if(mystack.top() == -1) 45 | s2 += tolower(s1[i]); 46 | } 47 | } 48 | cout< 34 | #include 35 | #include 36 | using namespace std; 37 | 38 | struct node { 39 | int hit; 40 | int score; 41 | }tank[10]; 42 | 43 | int N, M; 44 | 45 | int main() { 46 | while(scanf("%d %d", &N, &M) != EOF) { 47 | for(int i = 1; i <= N; i++) { 48 | tank[i].hit = 100; 49 | tank[i].score = 0; 50 | } 51 | 52 | for(int i = 0; i < M; i++) { 53 | int a, b; 54 | scanf("%d %d", &a, &b); 55 | if(tank[a].hit > 0) { 56 | if(tank[b].hit > 0) tank[a].score += 3; 57 | tank[b].hit -= 8; 58 | } 59 | } 60 | for(int i = 1; i <= N; i++) { 61 | if(tank[i].hit > 0) 62 | tank[i].score += (tank[i].hit / 2); 63 | } 64 | 65 | for(int i = 1; i <= N; i++) { 66 | printf("%d %d\n", tank[i].hit, tank[i].score); 67 | } 68 | } 69 | return 0; 70 | } 71 | -------------------------------------------------------------------------------- /300-399/358.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 358. Median of Medians 3 | 4 | Time limit per test: 0.25 second(s) 5 | Memory limit: 65536 kilobytes 6 | input: standard 7 | output: standard 8 | 9 | 10 | 11 | Vasya learned definition of median of three numbers. He says, "Median of three numbers is the number located in the middle when numbers are ordered in non-descending order". Subtle Pete gave him much more difficult task. Vasya has to find median of each of three triples and then find the median of three numbers he found. Please help Vasya with the task. 12 | 13 | Input 14 | The input file contains three lines. Each line contains three integers. Each number is not less than -1000 and is not greater than 1000. 15 | 16 | Output 17 | Print one number - median of three medians. 18 | ************************************************************************/ 19 | #include 20 | #include 21 | #include 22 | using namespace std; 23 | 24 | int a[5]; 25 | int ans[5]; 26 | 27 | int main() { 28 | 29 | for(int i = 0; i < 3; i++) { 30 | for(int j = 0; j < 3; j++) { 31 | scanf("%d", &a[j]); 32 | } 33 | sort(a, a + 3); 34 | ans[i] = a[1]; 35 | } 36 | 37 | sort(ans, ans + 3); 38 | printf("%d\n", ans[1]); 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /400-499/403.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 403. Scientific Problem 3 | 4 | Time limit per test: 0.25 second(s) 5 | Memory limit: 65536 kilobytes 6 | input: standard 7 | output: standard 8 | 9 | 10 | 11 | Once upon a time Professor Idioticideasinventor was travelling by train. Watching cheerless landscape outside the window, he decided to invent the theme of his new scientific work. All of a sudden a brilliant idea struck him: to develop an effective algorithm finding an integer number, which is x times less than the sum of all its integer positive predecessors, where number x is given. As far as he has no computer in the train, you have to solve this difficult problem. 12 | 13 | Input 14 | The first line of the input file contains an integer number x (1 ≤ x ≤ 109). 15 | 16 | Output 17 | Output an integer number — the answer to the problem. 18 | 19 | ************************************************************************/ 20 | #include 21 | #include 22 | #include 23 | using namespace std; 24 | 25 | int main() { 26 | int x; 27 | while(scanf("%d", &x) != EOF) { 28 | printf("%d\n", 2*x+1); 29 | } 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /400-499/404.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | 404. Fortune-telling with camomile 3 | 4 | Time limit per test: 0.25 second(s) 5 | Memory limit: 65536 kilobytes 6 | input: standard 7 | output: standard 8 | 9 | 10 | 11 | Masha loves Petya. The following question gives her no rest: does Petya love her too? The best way to find this out is a fortune-telling. There are plenty ways of fortune predicting, but Masha prefers fortune-telling with camomile more than others. It's rules are simple. You should take camomile into the right hand and start picking petals one by one. After each petal you should pronounce one phrase from the predefined list. Such phrases like "loves", "doesn't love", "loves sincerely", "doubts", "wants to date", "laughs" are usually used. Phrases are pronounced from the first to the last. The list of phrases is cyclic, so after the last phrase you should pronounce the first one. The phrase that you pronounce after the last petal will be an answer. 12 | 13 | Since Masha doesn't want to go to the forest and look for camomiles, she asks you to write the program which will simulate the process. 14 | 15 | Input 16 | First line of the input file contains two integer numbers N and M (1 ≤ N ≤ 100, 1 ≤ M ≤ 100), the number of petals and the number of phrases. Each of the following M lines contains one phrase. Phrases consist only of latin letters and their lengths are between 1 and 100. 17 | 18 | Output 19 | Output the resulting phrase. 20 | 21 | ************************************************************************/ 22 | #include 23 | 24 | int main() { 25 | int n, m; 26 | char s[101][101]; 27 | scanf ("%d%d", &n, &m); 28 | int i; 29 | for (i = 1; i <= m; ++i) { 30 | scanf ("%s", s[i]); 31 | } 32 | int love = (n%m == 0) ? m : n%m; 33 | printf("%s\n", s[love]); 34 | return 0; 35 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Zhenchao Gan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ID | TITLE | AC 2 | :----:|:----:|:----: 3 | [100](http://acm.sgu.ru/problem.php?contest=0&problem=100)|A+B|18881 4 | [102](http://acm.sgu.ru/problem.php?contest=0&problem=102)|Coprimes|7697 5 | [105](http://acm.sgu.ru/problem.php?contest=0&problem=105)|Div 3|6906 6 | [123](http://acm.sgu.ru/problem.php?contest=0&problem=123)|The sum|6185 7 | [115](http://acm.sgu.ru/problem.php?contest=0&problem=115)|Calendar|4336 8 | [135](http://acm.sgu.ru/problem.php?contest=0&problem=135)|Drawing Lines|4159 9 | [107](http://acm.sgu.ru/problem.php?contest=0&problem=107)|987654321 problem|4014 10 | [184](http://acm.sgu.ru/problem.php?contest=0&problem=184)|Patties|3998 11 | [113](http://acm.sgu.ru/problem.php?contest=0&problem=113)|Nearly prime numbers|3845 12 | [112](http://acm.sgu.ru/problem.php?contest=0&problem=112)|a^b - b^a|3673 13 | [101](http://acm.sgu.ru/problem.php?contest=0&problem=101)|Domino|3621 14 | [104](http://acm.sgu.ru/problem.php?contest=0&problem=104)|Little Shop of Flowers|3417 15 | [117](http://acm.sgu.ru/problem.php?contest=0&problem=117)|Counting|3290 16 | [127](http://acm.sgu.ru/problem.php?contest=0&problem=127)|Telephone directory|3282 17 | [118](http://acm.sgu.ru/problem.php?contest=0&problem=118)|Digital root|2874 18 | [126](http://acm.sgu.ru/problem.php?contest=0&problem=126)|Boxes|2836 19 | [276](http://acm.sgu.ru/problem.php?contest=0&problem=276)|Andrew's Troubles|2658 20 | [130](http://acm.sgu.ru/problem.php?contest=0&problem=130)|Circle|2555 21 | [154](http://acm.sgu.ru/problem.php?contest=0&problem=154)|Factorial|2529 22 | [114](http://acm.sgu.ru/problem.php?contest=0&problem=114)|Telecasting station|2476 23 | [222](http://acm.sgu.ru/problem.php?contest=0&problem=222)|Little Rooks|2354 24 | [116](http://acm.sgu.ru/problem.php?contest=0&problem=116)|Index of super-prime|2253 25 | [133](http://acm.sgu.ru/problem.php?contest=0&problem=133)|Border|2159 26 | [108](http://acm.sgu.ru/problem.php?contest=0&problem=108)|Self-numbers II|2149 27 | [144](http://acm.sgu.ru/problem.php?contest=0&problem=144)|Meeting|2121 28 | [175](http://acm.sgu.ru/problem.php?contest=0&problem=175)|Encoding|2032 29 | [231](http://acm.sgu.ru/problem.php?contest=0&problem=231)|Prime Sum|2003 30 | [134](http://acm.sgu.ru/problem.php?contest=0&problem=134)|Centroid|1931 31 | [180](http://acm.sgu.ru/problem.php?contest=0&problem=180)|Inversions|1906 32 | [106](http://acm.sgu.ru/problem.php?contest=0&problem=106)|The Equation|1884 33 | [111](http://acm.sgu.ru/problem.php?contest=0&problem=111)|Very simple problem|1879 34 | [181](http://acm.sgu.ru/problem.php?contest=0&problem=181)|X-Sequence|1838 35 | [169](http://acm.sgu.ru/problem.php?contest=0&problem=169)|Numbers|1800 36 | [103](http://acm.sgu.ru/problem.php?contest=0&problem=103)|Traffic Lights|1791 37 | [172](http://acm.sgu.ru/problem.php?contest=0&problem=172)|eXam|1779 38 | [109](http://acm.sgu.ru/problem.php?contest=0&problem=109)|Magic of David Copperfield II|1763 39 | [170](http://acm.sgu.ru/problem.php?contest=0&problem=170)|Particles|1732 40 | [143](http://acm.sgu.ru/problem.php?contest=0&problem=143)|Long Live the Queen|1708 41 | [163](http://acm.sgu.ru/problem.php?contest=0&problem=163)|Wise King|1702 42 | [297](http://acm.sgu.ru/problem.php?contest=0&problem=297)|Fair-play|1656 43 | [152](http://acm.sgu.ru/problem.php?contest=0&problem=152)|Making round|1631 44 | [124](http://acm.sgu.ru/problem.php?contest=0&problem=124)|Broken line|1615 45 | [168](http://acm.sgu.ru/problem.php?contest=0&problem=168)|Matrix|1570 46 | [149](http://acm.sgu.ru/problem.php?contest=0&problem=149)|Computer Network|1558 47 | [196](http://acm.sgu.ru/problem.php?contest=0&problem=196)|Matrix Multiplication|1552 48 | [302](http://acm.sgu.ru/problem.php?contest=0&problem=302)|BHTML 1.0|1539 49 | [146](http://acm.sgu.ru/problem.php?contest=0&problem=146)|The Runner|1535 50 | [179](http://acm.sgu.ru/problem.php?contest=0&problem=179)|Brackets light|1499 51 | [403](http://acm.sgu.ru/problem.php?contest=0&problem=403)|Scientific Problem|1435 52 | [131](http://acm.sgu.ru/problem.php?contest=0&problem=131)|Hardwood floor|1421 53 | [259](http://acm.sgu.ru/problem.php?contest=0&problem=259)|Printed PR|1416 54 | [139](http://acm.sgu.ru/problem.php?contest=0&problem=139)|Help Needed!|1377 55 | [119](http://acm.sgu.ru/problem.php?contest=0&problem=119)|Magic pairs|1361 56 | [125](http://acm.sgu.ru/problem.php?contest=0&problem=125)|Shtirlits|1312 57 | [358](http://acm.sgu.ru/problem.php?contest=0&problem=358)|Median of Medians|1292 58 | [193](http://acm.sgu.ru/problem.php?contest=0&problem=193)|Chinese Girls' Amusement|1281 59 | [316](http://acm.sgu.ru/problem.php?contest=0&problem=316)|Code Tanks|1280 60 | [223](http://acm.sgu.ru/problem.php?contest=0&problem=223)|Little Kings|1275 61 | [142](http://acm.sgu.ru/problem.php?contest=0&problem=142)|Keyword|1264 62 | [199](http://acm.sgu.ru/problem.php?contest=0&problem=199)|Beautiful People|1255 63 | [404](http://acm.sgu.ru/problem.php?contest=0&problem=404)|Fotrune-telling with camomile|1254 64 | [296](http://acm.sgu.ru/problem.php?contest=0&problem=296)|Sasha vs. Kate|1245 65 | [120](http://acm.sgu.ru/problem.php?contest=0&problem=120)|Arhipelago|1234 66 | [226](http://acm.sgu.ru/problem.php?contest=0&problem=226)|Colored graph|1230 67 | [186](http://acm.sgu.ru/problem.php?contest=0&problem=186)|The chain|1226 68 | [224](http://acm.sgu.ru/problem.php?contest=0&problem=224)|Little Queens|1185 69 | [194](http://acm.sgu.ru/problem.php?contest=0&problem=194)|Reactor Cooling|1182 70 | [174](http://acm.sgu.ru/problem.php?contest=0&problem=174)|Walls|1167 71 | [155](http://acm.sgu.ru/problem.php?contest=0&problem=155)|Cartesian Tree|1164 72 | [122](http://acm.sgu.ru/problem.php?contest=0&problem=122)|The book|1160 73 | [178](http://acm.sgu.ru/problem.php?contest=0&problem=178)|Chain|1142 74 | [460](http://acm.sgu.ru/problem.php?contest=0&problem=460)|Plural Form of Nouns|1131 75 | [188](http://acm.sgu.ru/problem.php?contest=0&problem=188)|Factory guard|1104 76 | [121](http://acm.sgu.ru/problem.php?contest=0&problem=121)|Bridges painting|1099 77 | [230](http://acm.sgu.ru/problem.php?contest=0&problem=230)|Weighings|1085 78 | [355](http://acm.sgu.ru/problem.php?contest=0&problem=355)|Numbers Painting|1080 79 | [148](http://acm.sgu.ru/problem.php?contest=0&problem=148)|B-Station|1072 80 | [299](http://acm.sgu.ru/problem.php?contest=0&problem=299)|Triangle|1071 81 | [274](http://acm.sgu.ru/problem.php?contest=0&problem=274)|Spam-filter|1050 82 | [249](http://acm.sgu.ru/problem.php?contest=0&problem=249)|Matrix|1045 83 | [190](http://acm.sgu.ru/problem.php?contest=0&problem=190)|Dominoes|1015 84 | [140](http://acm.sgu.ru/problem.php?contest=0&problem=140)|Integer Sequences|993 85 | [183](http://acm.sgu.ru/problem.php?contest=0&problem=183)|Painting the balls|991 86 | [160](http://acm.sgu.ru/problem.php?contest=0&problem=160)|Magic Multiplying Machine|989 87 | [176](http://acm.sgu.ru/problem.php?contest=0&problem=176)|Flow construction|989 88 | [177](http://acm.sgu.ru/problem.php?contest=0&problem=177)|Square|976 89 | [151](http://acm.sgu.ru/problem.php?contest=0&problem=151)|Construct a triangle|972 90 | [137](http://acm.sgu.ru/problem.php?contest=0&problem=137)|Funny Strings|959 91 | [153](http://acm.sgu.ru/problem.php?contest=0&problem=153)|Playing with matches|959 92 | [398](http://acm.sgu.ru/problem.php?contest=0&problem=398)|Friends of Friends|954 93 | [136](http://acm.sgu.ru/problem.php?contest=0&problem=136)|Erasing Edges|946 94 | [486](http://acm.sgu.ru/problem.php?contest=0&problem=486)|Bulls and Cows|932 95 | [185](http://acm.sgu.ru/problem.php?contest=0&problem=185)|Two shortest|930 96 | [246](http://acm.sgu.ru/problem.php?contest=0&problem=246)|Black & White|918 97 | [210](http://acm.sgu.ru/problem.php?contest=0&problem=210)|Beloved Sons|915 98 | [187](http://acm.sgu.ru/problem.php?contest=0&problem=187)|Twist and whirl -- want to cheat|895 99 | [271](http://acm.sgu.ru/problem.php?contest=0&problem=271)|Book Pile|891 100 | [207](http://acm.sgu.ru/problem.php?contest=0&problem=207)|Robbers|883 101 | [275](http://acm.sgu.ru/problem.php?contest=0&problem=275)|To xor or not to xor|883 102 | [220](http://acm.sgu.ru/problem.php?contest=0&problem=220)|Little Bishops|878 103 | [318](http://acm.sgu.ru/problem.php?contest=0&problem=318)|Grants|865 104 | [128](http://acm.sgu.ru/problem.php?contest=0&problem=128)|Snake|863 105 | [269](http://acm.sgu.ru/problem.php?contest=0&problem=269)|Rooks|861 106 | [195](http://acm.sgu.ru/problem.php?contest=0&problem=195)|New Year Bonus Grant|858 107 | [197](http://acm.sgu.ru/problem.php?contest=0&problem=197)|Nice Patterns Strike Back|849 108 | [239](http://acm.sgu.ru/problem.php?contest=0&problem=239)|Minesweeper|845 109 | [132](http://acm.sgu.ru/problem.php?contest=0&problem=132)|Another Chocolate Maniac|844 110 | [218](http://acm.sgu.ru/problem.php?contest=0&problem=218)|Unstable Systems|837 111 | [138](http://acm.sgu.ru/problem.php?contest=0&problem=138)|Games of Chess|829 112 | [353](http://acm.sgu.ru/problem.php?contest=0&problem=353)|Billing|826 113 | [203](http://acm.sgu.ru/problem.php?contest=0&problem=203)|Hyperhuffman|825 114 | [405](http://acm.sgu.ru/problem.php?contest=0&problem=405)|Totalizator|821 115 | [347](http://acm.sgu.ru/problem.php?contest=0&problem=347)|Join the Strings|815 116 | [443](http://acm.sgu.ru/problem.php?contest=0&problem=443)|Everlasting...?|810 117 | [519](http://acm.sgu.ru/problem.php?contest=0&problem=519)|3D City Model|800 118 | [375](http://acm.sgu.ru/problem.php?contest=0&problem=375)|Amplifiers|797 119 | [165](http://acm.sgu.ru/problem.php?contest=0&problem=165)|Basketball|786 120 | [242](http://acm.sgu.ru/problem.php?contest=0&problem=242)|Student's Morning|784 121 | [397](http://acm.sgu.ru/problem.php?contest=0&problem=397)|Text Editor|776 122 | [310](http://acm.sgu.ru/problem.php?contest=0&problem=310)|Hippopotamus|775 123 | [171](http://acm.sgu.ru/problem.php?contest=0&problem=171)|Sarov zones|763 124 | [362](http://acm.sgu.ru/problem.php?contest=0&problem=362)|Robot-Annihilator|760 125 | [162](http://acm.sgu.ru/problem.php?contest=0&problem=162)|Pyramids|755 126 | [344](http://acm.sgu.ru/problem.php?contest=0&problem=344)|Weed|754 127 | [110](http://acm.sgu.ru/problem.php?contest=0&problem=110)|Dungeon|735 128 | [406](http://acm.sgu.ru/problem.php?contest=0&problem=406)|Goggle|726 129 | [304](http://acm.sgu.ru/problem.php?contest=0&problem=304)|Mars Stomatology|718 130 | [533](http://acm.sgu.ru/problem.php?contest=0&problem=533)|Dice Tower|709 131 | [221](http://acm.sgu.ru/problem.php?contest=0&problem=221)|Big Bishops|707 132 | [499](http://acm.sgu.ru/problem.php?contest=0&problem=499)|Greatest Greatest Common Divisor|702 133 | [141](http://acm.sgu.ru/problem.php?contest=0&problem=141)|Jumping Joe|691 134 | [213](http://acm.sgu.ru/problem.php?contest=0&problem=213)|Strong Defence|684 135 | [374](http://acm.sgu.ru/problem.php?contest=0&problem=374)|Save Vasya|683 136 | [200](http://acm.sgu.ru/problem.php?contest=0&problem=200)|Cracking RSA|678 137 | [502](http://acm.sgu.ru/problem.php?contest=0&problem=502)|Digits Permutation|666 138 | [523](http://acm.sgu.ru/problem.php?contest=0&problem=523)|Elevator|662 139 | [158](http://acm.sgu.ru/problem.php?contest=0&problem=158)|Commuter Train|650 140 | [191](http://acm.sgu.ru/problem.php?contest=0&problem=191)|Exhibition|648 141 | [463](http://acm.sgu.ru/problem.php?contest=0&problem=463)|Walking around Berhattan|642 142 | [129](http://acm.sgu.ru/problem.php?contest=0&problem=129)|Inheritance|624 143 | [415](http://acm.sgu.ru/problem.php?contest=0&problem=415)|Necessary Coins|624 144 | [228](http://acm.sgu.ru/problem.php?contest=0&problem=228)|Archipelago|619 145 | [281](http://acm.sgu.ru/problem.php?contest=0&problem=281)|Championship|619 146 | [321](http://acm.sgu.ru/problem.php?contest=0&problem=321)|The Spy Network|614 147 | [551](http://acm.sgu.ru/problem.php?contest=0&problem=551)|Preparing Problem|588 148 | [357](http://acm.sgu.ru/problem.php?contest=0&problem=357)|Remote Control|581 149 | [150](http://acm.sgu.ru/problem.php?contest=0&problem=150)|Mr. Beetle II|579 150 | [365](http://acm.sgu.ru/problem.php?contest=0&problem=365)|Ships of the Desert|575 151 | [361](http://acm.sgu.ru/problem.php?contest=0&problem=361)|National Flag|574 152 | [546](http://acm.sgu.ru/problem.php?contest=0&problem=546)|Ternary Password|566 153 | [324](http://acm.sgu.ru/problem.php?contest=0&problem=324)|The Text Formatting|555 154 | [164](http://acm.sgu.ru/problem.php?contest=0&problem=164)|Airlines|546 155 | [518](http://acm.sgu.ru/problem.php?contest=0&problem=518)|Kidnapping|543 156 | [238](http://acm.sgu.ru/problem.php?contest=0&problem=238)|Uncle Vasya and Bags for Potatoes|537 157 | [444](http://acm.sgu.ru/problem.php?contest=0&problem=444)|Headstrong Student|536 158 | [253](http://acm.sgu.ru/problem.php?contest=0&problem=253)|Theodore Roosevelt|527 159 | [456](http://acm.sgu.ru/problem.php?contest=0&problem=456)|Annuity Payment Scheme|518 160 | [159](http://acm.sgu.ru/problem.php?contest=0&problem=159)|Self-Replicating Numbers|510 161 | [538](http://acm.sgu.ru/problem.php?contest=0&problem=538)|Emoticons|508 162 | [326](http://acm.sgu.ru/problem.php?contest=0&problem=326)|Perspective|506 163 | [291](http://acm.sgu.ru/problem.php?contest=0&problem=291)|Evolution|499 164 | [359](http://acm.sgu.ru/problem.php?contest=0&problem=359)|Pointers|490 165 | [256](http://acm.sgu.ru/problem.php?contest=0&problem=256)|Balloons|488 166 | [346](http://acm.sgu.ru/problem.php?contest=0&problem=346)|Snooker|487 167 | [317](http://acm.sgu.ru/problem.php?contest=0&problem=317)|Fast Ride|484 168 | [145](http://acm.sgu.ru/problem.php?contest=0&problem=145)|Strange People|482 169 | [156](http://acm.sgu.ru/problem.php?contest=0&problem=156)|Strange Graph|479 170 | [478](http://acm.sgu.ru/problem.php?contest=0&problem=478)|Excursion|475 171 | [273](http://acm.sgu.ru/problem.php?contest=0&problem=273)|Game Po|473 172 | [311](http://acm.sgu.ru/problem.php?contest=0&problem=311)|Ice-cream Tycoon|470 173 | [248](http://acm.sgu.ru/problem.php?contest=0&problem=248)|Integer Linear Programming|469 174 | [531](http://acm.sgu.ru/problem.php?contest=0&problem=531)|Bonnie and Clyde|465 175 | [506](http://acm.sgu.ru/problem.php?contest=0&problem=506)|Subsequences Of Substrings|464 176 | [260](http://acm.sgu.ru/problem.php?contest=0&problem=260)|Puzzle|459 177 | [300](http://acm.sgu.ru/problem.php?contest=0&problem=300)|Train|458 178 | [484](http://acm.sgu.ru/problem.php?contest=0&problem=484)|Kola|458 179 | [214](http://acm.sgu.ru/problem.php?contest=0&problem=214)|Weird Dissimilarity|456 180 | [255](http://acm.sgu.ru/problem.php?contest=0&problem=255)|Winsock 3 Beta|455 181 | [520](http://acm.sgu.ru/problem.php?contest=0&problem=520)|Fire in the Country|452 182 | [157](http://acm.sgu.ru/problem.php?contest=0&problem=157)|Patience|448 183 | [167](http://acm.sgu.ru/problem.php?contest=0&problem=167)|I-country|445 184 | [496](http://acm.sgu.ru/problem.php?contest=0&problem=496)|L-Shapes|441 185 | [206](http://acm.sgu.ru/problem.php?contest=0&problem=206)|Roads|436 186 | [407](http://acm.sgu.ru/problem.php?contest=0&problem=407)|Number of Paths in the Empire|434 187 | [339](http://acm.sgu.ru/problem.php?contest=0&problem=339)|Segments|429 188 | [201](http://acm.sgu.ru/problem.php?contest=0&problem=201)|Non Absorbing DFA|425 189 | [202](http://acm.sgu.ru/problem.php?contest=0&problem=202)|The Towers of Hanoi Revisited|424 190 | [236](http://acm.sgu.ru/problem.php?contest=0&problem=236)|Greedy Path|421 191 | [409](http://acm.sgu.ru/problem.php?contest=0&problem=409)|Berland Flag|418 192 | [217](http://acm.sgu.ru/problem.php?contest=0&problem=217)|Two Cylinders|416 193 | [294](http://acm.sgu.ru/problem.php?contest=0&problem=294)|He's Circles|415 194 | [288](http://acm.sgu.ru/problem.php?contest=0&problem=288)|Best Tournament Schedule|414 195 | [198](http://acm.sgu.ru/problem.php?contest=0&problem=198)|Get Out!|413 196 | [322](http://acm.sgu.ru/problem.php?contest=0&problem=322)|The Great Union|411 197 | [408](http://acm.sgu.ru/problem.php?contest=0&problem=408)|Game with Points|410 198 | [377](http://acm.sgu.ru/problem.php?contest=0&problem=377)|The Lesson of Physical Culture|404 199 | [301](http://acm.sgu.ru/problem.php?contest=0&problem=301)|Boring. Hot. Summer...|402 200 | [488](http://acm.sgu.ru/problem.php?contest=0&problem=488)|Dales and Hills|402 201 | [495](http://acm.sgu.ru/problem.php?contest=0&problem=495)|Kids and Prizes|395 202 | [280](http://acm.sgu.ru/problem.php?contest=0&problem=280)|Trade centers|394 203 | [289](http://acm.sgu.ru/problem.php?contest=0&problem=289)|Challenging Tic-Tac-Toe|393 204 | [524](http://acm.sgu.ru/problem.php?contest=0&problem=524)|Buoys|384 205 | [225](http://acm.sgu.ru/problem.php?contest=0&problem=225)|Little Knights|381 206 | [240](http://acm.sgu.ru/problem.php?contest=0&problem=240)|Runaway|380 207 | [192](http://acm.sgu.ru/problem.php?contest=0&problem=192)|RGB|378 208 | [411](http://acm.sgu.ru/problem.php?contest=0&problem=411)|Petya the Hero|372 209 | [527](http://acm.sgu.ru/problem.php?contest=0&problem=527)|Explode 'Em All|368 210 | [182](http://acm.sgu.ru/problem.php?contest=0&problem=182)|Open the brackets|364 211 | [370](http://acm.sgu.ru/problem.php?contest=0&problem=370)|Rifleman|364 212 | [455](http://acm.sgu.ru/problem.php?contest=0&problem=455)|Sequence analysis|361 213 | [205](http://acm.sgu.ru/problem.php?contest=0&problem=205)|Quantization Problem|359 214 | [254](http://acm.sgu.ru/problem.php?contest=0&problem=254)|Strange Random|358 215 | [424](http://acm.sgu.ru/problem.php?contest=0&problem=424)|Beautiful Graph|358 216 | [507](http://acm.sgu.ru/problem.php?contest=0&problem=507)|Treediff|355 217 | [325](http://acm.sgu.ru/problem.php?contest=0&problem=325)|Palindrome|354 218 | [232](http://acm.sgu.ru/problem.php?contest=0&problem=232)|Infinite Fraction|352 219 | [262](http://acm.sgu.ru/problem.php?contest=0&problem=262)|Symbol Recognition|347 220 | [483](http://acm.sgu.ru/problem.php?contest=0&problem=483)|Jealous Cucumber|347 221 | [267](http://acm.sgu.ru/problem.php?contest=0&problem=267)|Optimist vs. Pessimist|346 222 | [337](http://acm.sgu.ru/problem.php?contest=0&problem=337)|Keven|342 223 | [458](http://acm.sgu.ru/problem.php?contest=0&problem=458)|The Monochrome Picture|342 224 | [305](http://acm.sgu.ru/problem.php?contest=0&problem=305)|Exhibition|340 225 | [548](http://acm.sgu.ru/problem.php?contest=0&problem=548)|Dragons and Princesses|340 226 | [356](http://acm.sgu.ru/problem.php?contest=0&problem=356)|Extrasensory Perception|339 227 | [147](http://acm.sgu.ru/problem.php?contest=0&problem=147)|Black-white king|336 228 | [363](http://acm.sgu.ru/problem.php?contest=0&problem=363)|Baggage room|323 229 | [295](http://acm.sgu.ru/problem.php?contest=0&problem=295)|Identifier Duplicated!|319 230 | [479](http://acm.sgu.ru/problem.php?contest=0&problem=479)|Funny Feature|318 231 | [350](http://acm.sgu.ru/problem.php?contest=0&problem=350)|XOR-omania|314 232 | [368](http://acm.sgu.ru/problem.php?contest=0&problem=368)|Tests|314 233 | [252](http://acm.sgu.ru/problem.php?contest=0&problem=252)|Railway Communication|309 234 | [216](http://acm.sgu.ru/problem.php?contest=0&problem=216)|Royal Federation|308 235 | [328](http://acm.sgu.ru/problem.php?contest=0&problem=328)|A Coloring Game|308 236 | [234](http://acm.sgu.ru/problem.php?contest=0&problem=234)|Black-White King Strikes Back|307 237 | [549](http://acm.sgu.ru/problem.php?contest=0&problem=549)|Dumbbells|304 238 | [379](http://acm.sgu.ru/problem.php?contest=0&problem=379)|Elevator|301 239 | [208](http://acm.sgu.ru/problem.php?contest=0&problem=208)|Toral Tickets|295 240 | [219](http://acm.sgu.ru/problem.php?contest=0&problem=219)|Synchrograph|295 241 | [261](http://acm.sgu.ru/problem.php?contest=0&problem=261)|Discrete Roots|288 242 | [441](http://acm.sgu.ru/problem.php?contest=0&problem=441)|Set Division|288 243 | [532](http://acm.sgu.ru/problem.php?contest=0&problem=532)|Building Foundation|286 244 | [323](http://acm.sgu.ru/problem.php?contest=0&problem=323)|Aviamachinations|284 245 | [211](http://acm.sgu.ru/problem.php?contest=0&problem=211)|Strange Counter|283 246 | [166](http://acm.sgu.ru/problem.php?contest=0&problem=166)|Editor|278 247 | [286](http://acm.sgu.ru/problem.php?contest=0&problem=286)|Ancient decoration|278 248 | [189](http://acm.sgu.ru/problem.php?contest=0&problem=189)|Perl-like Substr|276 249 | [354](http://acm.sgu.ru/problem.php?contest=0&problem=354)|Just Matrix|276 250 | [369](http://acm.sgu.ru/problem.php?contest=0&problem=369)|Game|275 251 | [212](http://acm.sgu.ru/problem.php?contest=0&problem=212)|Data Transmission|274 252 | [462](http://acm.sgu.ru/problem.php?contest=0&problem=462)|Electrician|274 253 | [247](http://acm.sgu.ru/problem.php?contest=0&problem=247)|Difficult Choice|270 254 | [417](http://acm.sgu.ru/problem.php?contest=0&problem=417)|Heavy Disc|267 255 | [229](http://acm.sgu.ru/problem.php?contest=0&problem=229)|Divide and conquer|264 256 | [244](http://acm.sgu.ru/problem.php?contest=0&problem=244)|Height, Bisector and Median|264 257 | [492](http://acm.sgu.ru/problem.php?contest=0&problem=492)|Hotel in Ves Lagos|264 258 | [270](http://acm.sgu.ru/problem.php?contest=0&problem=270)|Thimbles|263 259 | [438](http://acm.sgu.ru/problem.php?contest=0&problem=438)|The Glorious Karlutka River =)|263 260 | [309](http://acm.sgu.ru/problem.php?contest=0&problem=309)|Real Fun|262 261 | [319](http://acm.sgu.ru/problem.php?contest=0&problem=319)|Kalevich Strikes Back|256 262 | [264](http://acm.sgu.ru/problem.php?contest=0&problem=264)|Travel|253 263 | [461](http://acm.sgu.ru/problem.php?contest=0&problem=461)|Wiki Lists|253 264 | [525](http://acm.sgu.ru/problem.php?contest=0&problem=525)|Revolutionary Roads|253 265 | [552](http://acm.sgu.ru/problem.php?contest=0&problem=552)|Database Optimization|253 266 | [508](http://acm.sgu.ru/problem.php?contest=0&problem=508)|Black-White Balls|251 267 | [330](http://acm.sgu.ru/problem.php?contest=0&problem=330)|Numbers|247 268 | [410](http://acm.sgu.ru/problem.php?contest=0&problem=410)|Galaxy in danger|247 269 | [521](http://acm.sgu.ru/problem.php?contest=0&problem=521)|"North-East"|244 270 | [173](http://acm.sgu.ru/problem.php?contest=0&problem=173)|Coins|243 271 | [416](http://acm.sgu.ru/problem.php?contest=0&problem=416)|Optimal Dartboard|241 272 | [367](http://acm.sgu.ru/problem.php?contest=0&problem=367)|Contest|240 273 | [209](http://acm.sgu.ru/problem.php?contest=0&problem=209)|Areas|235 274 | [348](http://acm.sgu.ru/problem.php?contest=0&problem=348)|Twisting the Number|235 275 | [258](http://acm.sgu.ru/problem.php?contest=0&problem=258)|Almost Lucky Numbers|230 276 | [536](http://acm.sgu.ru/problem.php?contest=0&problem=536)|Berland Chess|227 277 | [263](http://acm.sgu.ru/problem.php?contest=0&problem=263)|Towers|225 278 | [243](http://acm.sgu.ru/problem.php?contest=0&problem=243)|Broken Chessboard|224 279 | [282](http://acm.sgu.ru/problem.php?contest=0&problem=282)|Isomorphism|223 280 | [515](http://acm.sgu.ru/problem.php?contest=0&problem=515)|Recover Path|223 281 | [342](http://acm.sgu.ru/problem.php?contest=0&problem=342)|Reihenfolge|222 282 | [285](http://acm.sgu.ru/problem.php?contest=0&problem=285)|What? Where? When?|220 283 | [257](http://acm.sgu.ru/problem.php?contest=0&problem=257)|Debt|219 284 | [372](http://acm.sgu.ru/problem.php?contest=0&problem=372)|Tea Party|219 285 | [482](http://acm.sgu.ru/problem.php?contest=0&problem=482)|Impudent Thief|218 286 | [489](http://acm.sgu.ru/problem.php?contest=0&problem=489)|Extremal Permutations|211 287 | [251](http://acm.sgu.ru/problem.php?contest=0&problem=251)|Polymania|205 288 | [476](http://acm.sgu.ru/problem.php?contest=0&problem=476)|Coach`s trouble|204 289 | [537](http://acm.sgu.ru/problem.php?contest=0&problem=537)|Divisibility|203 290 | [307](http://acm.sgu.ru/problem.php?contest=0&problem=307)|Cipher|198 291 | [340](http://acm.sgu.ru/problem.php?contest=0&problem=340)|Tex2HTML|198 292 | [204](http://acm.sgu.ru/problem.php?contest=0&problem=204)|Little Jumper|190 293 | [272](http://acm.sgu.ru/problem.php?contest=0&problem=272)|Evacuation plan|187 294 | [250](http://acm.sgu.ru/problem.php?contest=0&problem=250)|Constructive Plan|186 295 | [505](http://acm.sgu.ru/problem.php?contest=0&problem=505)|Prefixes and suffixes|185 296 | [278](http://acm.sgu.ru/problem.php?contest=0&problem=278)|Fuel|184 297 | [298](http://acm.sgu.ru/problem.php?contest=0&problem=298)|King Berl VI|184 298 | [491](http://acm.sgu.ru/problem.php?contest=0&problem=491)|Game for Little Johnny|184 299 | [320](http://acm.sgu.ru/problem.php?contest=0&problem=320)|The Influence of the Mafia|183 300 | [384](http://acm.sgu.ru/problem.php?contest=0&problem=384)|Country|183 301 | [235](http://acm.sgu.ru/problem.php?contest=0&problem=235)|The Queen|181 302 | [284](http://acm.sgu.ru/problem.php?contest=0&problem=284)|Grammar|181 303 | [510](http://acm.sgu.ru/problem.php?contest=0&problem=510)|Distinct Substrings|180 304 | [490](http://acm.sgu.ru/problem.php?contest=0&problem=490)|Figure and Spots|177 305 | [161](http://acm.sgu.ru/problem.php?contest=0&problem=161)|Intuitionistic Logic|176 306 | [360](http://acm.sgu.ru/problem.php?contest=0&problem=360)|B++ Interpreter|176 307 | [394](http://acm.sgu.ru/problem.php?contest=0&problem=394)|Berhatton|176 308 | [553](http://acm.sgu.ru/problem.php?contest=0&problem=553)|Sultan's Pearls|175 309 | [389](http://acm.sgu.ru/problem.php?contest=0&problem=389)|Strange Planet|174 310 | [215](http://acm.sgu.ru/problem.php?contest=0&problem=215)|PL/Cool|172 311 | [334](http://acm.sgu.ru/problem.php?contest=0&problem=334)|Tiny Puzzle|172 312 | [428](http://acm.sgu.ru/problem.php?contest=0&problem=428)|Rebus|172 313 | [422](http://acm.sgu.ru/problem.php?contest=0&problem=422)|Fast Typing|171 314 | [332](http://acm.sgu.ru/problem.php?contest=0&problem=332)|Largest Circle|169 315 | [467](http://acm.sgu.ru/problem.php?contest=0&problem=467)|Chessmaster|169 316 | [366](http://acm.sgu.ru/problem.php?contest=0&problem=366)|Computer Game|168 317 | [376](http://acm.sgu.ru/problem.php?contest=0&problem=376)|Berland All-Round Competitions|167 318 | [227](http://acm.sgu.ru/problem.php?contest=0&problem=227)|The art to the broad masses!|162 319 | [497](http://acm.sgu.ru/problem.php?contest=0&problem=497)|Abelian Groups|162 320 | [241](http://acm.sgu.ru/problem.php?contest=0&problem=241)|The United Fields of Chessboardia|161 321 | [277](http://acm.sgu.ru/problem.php?contest=0&problem=277)|Heroes|160 322 | [287](http://acm.sgu.ru/problem.php?contest=0&problem=287)|Amusing Qc Machine|158 323 | [402](http://acm.sgu.ru/problem.php?contest=0&problem=402)|Terrorists in Berland|153 324 | [487](http://acm.sgu.ru/problem.php?contest=0&problem=487)|Courier|151 325 | [233](http://acm.sgu.ru/problem.php?contest=0&problem=233)|The Greatest Angle|150 326 | [380](http://acm.sgu.ru/problem.php?contest=0&problem=380)|Synchronised Alpinism|150 327 | [390](http://acm.sgu.ru/problem.php?contest=0&problem=390)|Tickets|150 328 | [396](http://acm.sgu.ru/problem.php?contest=0&problem=396)|Dance it up!|149 329 | [385](http://acm.sgu.ru/problem.php?contest=0&problem=385)|Highlander|147 330 | [283](http://acm.sgu.ru/problem.php?contest=0&problem=283)|Mechanics|145 331 | [292](http://acm.sgu.ru/problem.php?contest=0&problem=292)|Field for the Cemetery|144 332 | [504](http://acm.sgu.ru/problem.php?contest=0&problem=504)|Square Palindrome|144 333 | [446](http://acm.sgu.ru/problem.php?contest=0&problem=446)|Rotation Estimation|139 334 | [313](http://acm.sgu.ru/problem.php?contest=0&problem=313)|Circular Railway|138 335 | [432](http://acm.sgu.ru/problem.php?contest=0&problem=432)|XYZX 2009|138 336 | [434](http://acm.sgu.ru/problem.php?contest=0&problem=434)|Chemists|138 337 | [327](http://acm.sgu.ru/problem.php?contest=0&problem=327)|Yet Another Palindrome|137 338 | [413](http://acm.sgu.ru/problem.php?contest=0&problem=413)|Berland Division|137 339 | [279](http://acm.sgu.ru/problem.php?contest=0&problem=279)|Bipermutations|136 340 | [453](http://acm.sgu.ru/problem.php?contest=0&problem=453)|Meetings|135 341 | [237](http://acm.sgu.ru/problem.php?contest=0&problem=237)|Galaxy X: Episode I - Masters of Mind|133 342 | [336](http://acm.sgu.ru/problem.php?contest=0&problem=336)|Elections|133 343 | [511](http://acm.sgu.ru/problem.php?contest=0&problem=511)|Fermat's Last Theorem|132 344 | [399](http://acm.sgu.ru/problem.php?contest=0&problem=399)|Berodoskar Development|129 345 | [447](http://acm.sgu.ru/problem.php?contest=0&problem=447)|Optimal Rest|125 346 | [364](http://acm.sgu.ru/problem.php?contest=0&problem=364)|Lemmings|124 347 | [465](http://acm.sgu.ru/problem.php?contest=0&problem=465)|Fire Station Building|122 348 | [265](http://acm.sgu.ru/problem.php?contest=0&problem=265)|Wizards|121 349 | [381](http://acm.sgu.ru/problem.php?contest=0&problem=381)|Bidirected Graph|121 350 | [429](http://acm.sgu.ru/problem.php?contest=0&problem=429)|Problem Stacks|120 351 | [473](http://acm.sgu.ru/problem.php?contest=0&problem=473)|Droid formation|120 352 | [329](http://acm.sgu.ru/problem.php?contest=0&problem=329)|Black-and-White Triangle|119 353 | [352](http://acm.sgu.ru/problem.php?contest=0&problem=352)|Beerland Attacks|118 354 | [393](http://acm.sgu.ru/problem.php?contest=0&problem=393)|Bergamot Problem|117 355 | [445](http://acm.sgu.ru/problem.php?contest=0&problem=445)|Dig or Climb|117 356 | [433](http://acm.sgu.ru/problem.php?contest=0&problem=433)|Japhshan and Ramshut|112 357 | [439](http://acm.sgu.ru/problem.php?contest=0&problem=439)|A Secret Book|108 358 | [544](http://acm.sgu.ru/problem.php?contest=0&problem=544)|Chess Championship|107 359 | [459](http://acm.sgu.ru/problem.php?contest=0&problem=459)|Choreographer Problem|104 360 | [349](http://acm.sgu.ru/problem.php?contest=0&problem=349)|Wolves and Sheep|101 361 | [371](http://acm.sgu.ru/problem.php?contest=0&problem=371)|Subway|100 362 | [539](http://acm.sgu.ru/problem.php?contest=0&problem=539)|Multiswap Sorting|100 363 | [423](http://acm.sgu.ru/problem.php?contest=0&problem=423)|Battle|99 364 | [512](http://acm.sgu.ru/problem.php?contest=0&problem=512)|Friendly Points|99 365 | [290](http://acm.sgu.ru/problem.php?contest=0&problem=290)|Defend the Milky Way|97 366 | [303](http://acm.sgu.ru/problem.php?contest=0&problem=303)|Great Berland Wall|97 367 | [448](http://acm.sgu.ru/problem.php?contest=0&problem=448)|Controlled Tournament|97 368 | [514](http://acm.sgu.ru/problem.php?contest=0&problem=514)|Polygon|97 369 | [338](http://acm.sgu.ru/problem.php?contest=0&problem=338)|Casino|94 370 | [426](http://acm.sgu.ru/problem.php?contest=0&problem=426)|Double Cyclic|94 371 | [468](http://acm.sgu.ru/problem.php?contest=0&problem=468)|A bit of classic|94 372 | [268](http://acm.sgu.ru/problem.php?contest=0&problem=268)|Hyper Almost Permutative String|93 373 | [293](http://acm.sgu.ru/problem.php?contest=0&problem=293)|Game with Q an C|91 374 | [534](http://acm.sgu.ru/problem.php?contest=0&problem=534)|Computer Network|90 375 | [306](http://acm.sgu.ru/problem.php?contest=0&problem=306)|Balance|89 376 | [335](http://acm.sgu.ru/problem.php?contest=0&problem=335)|Thiefs and Cops|88 377 | [442](http://acm.sgu.ru/problem.php?contest=0&problem=442)|X + R(X) = N|87 378 | [412](http://acm.sgu.ru/problem.php?contest=0&problem=412)|Expedition|83 379 | [382](http://acm.sgu.ru/problem.php?contest=0&problem=382)|Cantor Function|82 380 | [266](http://acm.sgu.ru/problem.php?contest=0&problem=266)|Berlion|78 381 | [449](http://acm.sgu.ru/problem.php?contest=0&problem=449)|Dendrograms|78 382 | [345](http://acm.sgu.ru/problem.php?contest=0&problem=345)|Revolution|77 383 | [425](http://acm.sgu.ru/problem.php?contest=0&problem=425)|Control Function|75 384 | [540](http://acm.sgu.ru/problem.php?contest=0&problem=540)|Traffic Lights|75 385 | [481](http://acm.sgu.ru/problem.php?contest=0&problem=481)|Hero of Our Time|73 386 | [245](http://acm.sgu.ru/problem.php?contest=0&problem=245)|Black-White Army|71 387 | [420](http://acm.sgu.ru/problem.php?contest=0&problem=420)|Number Permutations|70 388 | [517](http://acm.sgu.ru/problem.php?contest=0&problem=517)|Cornerless Tiling|68 389 | [308](http://acm.sgu.ru/problem.php?contest=0&problem=308)|Hyperboloid Distance|67 390 | [388](http://acm.sgu.ru/problem.php?contest=0&problem=388)|Soap Opera|67 391 | [475](http://acm.sgu.ru/problem.php?contest=0&problem=475)|Be a Smart Raftsman|67 392 | [550](http://acm.sgu.ru/problem.php?contest=0&problem=550)|Tree Queries Online|67 393 | [480](http://acm.sgu.ru/problem.php?contest=0&problem=480)|Gena`s Soul Cakes|66 394 | [513](http://acm.sgu.ru/problem.php?contest=0&problem=513)|Maximal Clique|63 395 | [314](http://acm.sgu.ru/problem.php?contest=0&problem=314)|Shortest Paths|62 396 | [435](http://acm.sgu.ru/problem.php?contest=0&problem=435)|UFO Circles|62 397 | [454](http://acm.sgu.ru/problem.php?contest=0&problem=454)|Kakuro|62 398 | [477](http://acm.sgu.ru/problem.php?contest=0&problem=477)|Doors|59 399 | [529](http://acm.sgu.ru/problem.php?contest=0&problem=529)|It's Time to Repair the Roads|59 400 | [503](http://acm.sgu.ru/problem.php?contest=0&problem=503)|Running City|57 401 | [391](http://acm.sgu.ru/problem.php?contest=0&problem=391)|Mr. X|56 402 | [341](http://acm.sgu.ru/problem.php?contest=0&problem=341)|Circuits|55 403 | [414](http://acm.sgu.ru/problem.php?contest=0&problem=414)|Orthogonal Circles|55 404 | [431](http://acm.sgu.ru/problem.php?contest=0&problem=431)|Wildcards|55 405 | [315](http://acm.sgu.ru/problem.php?contest=0&problem=315)|The Highway Belt|54 406 | [383](http://acm.sgu.ru/problem.php?contest=0&problem=383)|Caravans|54 407 | [485](http://acm.sgu.ru/problem.php?contest=0&problem=485)|Arrays|54 408 | [542](http://acm.sgu.ru/problem.php?contest=0&problem=542)|Gena vs Petya|54 409 | [401](http://acm.sgu.ru/problem.php?contest=0&problem=401)|Geologist Dubrovsky|53 410 | [509](http://acm.sgu.ru/problem.php?contest=0&problem=509)|Chameleons All Around|53 411 | [530](http://acm.sgu.ru/problem.php?contest=0&problem=530)|Recruiting|52 412 | [421](http://acm.sgu.ru/problem.php?contest=0&problem=421)|k-th Product|51 413 | [343](http://acm.sgu.ru/problem.php?contest=0&problem=343)|VaR|50 414 | [535](http://acm.sgu.ru/problem.php?contest=0&problem=535)|Dirty Dishes|47 415 | [373](http://acm.sgu.ru/problem.php?contest=0&problem=373)|Carlsson vs. Winnie-the-Pooh|46 416 | [392](http://acm.sgu.ru/problem.php?contest=0&problem=392)|Cyclic Troubles|46 417 | [522](http://acm.sgu.ru/problem.php?contest=0&problem=522)|Oil Wells|46 418 | [493](http://acm.sgu.ru/problem.php?contest=0&problem=493)|Illumination of Buildings|45 419 | [541](http://acm.sgu.ru/problem.php?contest=0&problem=541)|BR Privatization|44 420 | [437](http://acm.sgu.ru/problem.php?contest=0&problem=437)|Hexodoku|43 421 | [528](http://acm.sgu.ru/problem.php?contest=0&problem=528)|Bencoding|43 422 | [543](http://acm.sgu.ru/problem.php?contest=0&problem=543)|Cafe|43 423 | [471](http://acm.sgu.ru/problem.php?contest=0&problem=471)|Funny Game|41 424 | [312](http://acm.sgu.ru/problem.php?contest=0&problem=312)|4-3 King|39 425 | [395](http://acm.sgu.ru/problem.php?contest=0&problem=395)|"Binary Cat" Club|39 426 | [331](http://acm.sgu.ru/problem.php?contest=0&problem=331)|Traffic Jam|38 427 | [386](http://acm.sgu.ru/problem.php?contest=0&problem=386)|Happy Birthday, Jedi Knight!|37 428 | [400](http://acm.sgu.ru/problem.php?contest=0&problem=400)|The last hour of the contest|37 429 | [427](http://acm.sgu.ru/problem.php?contest=0&problem=427)|Hamiltonian Polyhedron|36 430 | [436](http://acm.sgu.ru/problem.php?contest=0&problem=436)|The Diputs notation|36 431 | [440](http://acm.sgu.ru/problem.php?contest=0&problem=440)|Moles and Holes|35 432 | [466](http://acm.sgu.ru/problem.php?contest=0&problem=466)|Parking at Secret Object|35 433 | [472](http://acm.sgu.ru/problem.php?contest=0&problem=472)|Sokoban|34 434 | [378](http://acm.sgu.ru/problem.php?contest=0&problem=378)|Save the Fisher|32 435 | [498](http://acm.sgu.ru/problem.php?contest=0&problem=498)|Coins|32 436 | [457](http://acm.sgu.ru/problem.php?contest=0&problem=457)|Snow in Berland|31 437 | [430](http://acm.sgu.ru/problem.php?contest=0&problem=430)|Unit-distance Graph|30 438 | [474](http://acm.sgu.ru/problem.php?contest=0&problem=474)|All for Love|29 439 | [494](http://acm.sgu.ru/problem.php?contest=0&problem=494)|Journal|29 440 | [333](http://acm.sgu.ru/problem.php?contest=0&problem=333)|Random Shooting|28 441 | [387](http://acm.sgu.ru/problem.php?contest=0&problem=387)|Lazy Judges|27 442 | [469](http://acm.sgu.ru/problem.php?contest=0&problem=469)|Ghostbusters|27 443 | [451](http://acm.sgu.ru/problem.php?contest=0&problem=451)|Cousin's Aunt|26 444 | [526](http://acm.sgu.ru/problem.php?contest=0&problem=526)|Running Hero|26 445 | [470](http://acm.sgu.ru/problem.php?contest=0&problem=470)|The Death Cube|25 446 | [450](http://acm.sgu.ru/problem.php?contest=0&problem=450)|Ramen Shop|24 447 | [501](http://acm.sgu.ru/problem.php?contest=0&problem=501)|Octahedron And Dominoes|23 448 | [547](http://acm.sgu.ru/problem.php?contest=0&problem=547)|Divide the Kingdom|21 449 | [419](http://acm.sgu.ru/problem.php?contest=0&problem=419)|Hexagonal Walkaround|20 450 | [500](http://acm.sgu.ru/problem.php?contest=0&problem=500)|Circular Island|20 451 | [351](http://acm.sgu.ru/problem.php?contest=0&problem=351)|A Mission for a Scout|17 452 | [516](http://acm.sgu.ru/problem.php?contest=0&problem=516)|Schedule|16 453 | [418](http://acm.sgu.ru/problem.php?contest=0&problem=418)|Deducing Grammar|11 454 | [464](http://acm.sgu.ru/problem.php?contest=0&problem=464)|Optimal bribing|8 455 | [545](http://acm.sgu.ru/problem.php?contest=0&problem=545)|Cut the rope, another rope and so on!|7 456 | [452](http://acm.sgu.ru/problem.php?contest=0&problem=452)|Colony Maintenance|5 457 | -------------------------------------------------------------------------------- /RankAC.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding=utf-8 3 | 4 | import urllib2 5 | 6 | result = [] 7 | 8 | for i in range(1,6): 9 | urlname = 'http://acm.sgu.ru/problemset.php?contest=0&volume=' + str(i) 10 | print urlname 11 | urlfile = urllib2.urlopen(urlname) #以文件的形式打开一个网页 12 | html = urlfile.read() #从网页文件中读html 13 | start = 0 14 | while start < len(html): 15 | pos = html.find('problem.php?contest=0&problem=', start); 16 | if pos < 1: 17 | break 18 | 19 | pos1 = html.find('>', pos) 20 | pos2 = html.find('<', pos) 21 | id = html[pos1+1:pos2] 22 | 23 | pos3 = html.find(' ', pos) 24 | pos4 = html.find('<', pos3) 25 | name = html[pos3+6:pos4] 26 | 27 | pos5 = html.find('status.php', pos4) 28 | pos6 = html.find('>', pos5) 29 | pos7 = html.find('<', pos5) 30 | ac = int(html[pos6+1:pos7]) 31 | tup = (id,name,ac) 32 | result.append(tup) 33 | start = pos7 34 | 35 | result.sort(lambda y,x:cmp(x[2],y[2])) 36 | 37 | file_object = open('README.md', 'w') 38 | file_object.write('ID | TITLE | AC\n') 39 | file_object.write(':----:|:----:|:----:\n') 40 | for item in result: 41 | file_object.write('[' + item[0] + ']' + '(http://acm.sgu.ru/problem.php?contest=0&problem=' + item[0] + ')' + '|' + item[1] + '|' + str(item[2]) + '\n') 42 | 43 | file_object.close( ) --------------------------------------------------------------------------------