├── README.md ├── 110B - Lucky String.py ├── 195A - Let's Watch Football.cpp ├── 327B - Hungry Sequence.py ├── 182B - Vasya's Calendar.cpp ├── 194A - Exams.cpp ├── 84A - Toy Army.cpp ├── 199A - Hexadecimal's theorem.py ├── 50A - Domino piling.cpp ├── 47A - Triangular numbers.py ├── 124A - The number of positions.cpp ├── 27A - Next Test.py ├── 4C - Registration System.py ├── 216A - Tiling with Hexagons.cpp ├── 281A - Word Capitalization.cpp ├── 268B - Buttons.cpp ├── 333A - Secrets.cpp ├── 1A - Theater Square.cpp ├── 339A - Helpful Maths.py ├── 151A - Soft Drinking.cpp ├── 122B - Lucky Substring.py ├── 257B - Playing Cubes.cpp ├── 340A - The Wall.py ├── 4A - Watermelon.cpp ├── 221A - Little Elephant and Function.cpp ├── 246B - Increase and Decrease.cpp ├── 9A - Die Roll.cpp ├── 289A - Polo the Penguin and Segments.cpp ├── 12A - Super Agent.cpp ├── 133A - HQ9+.cpp ├── 190A - Vasya and the Bus.cpp ├── 200B - Drinks.cpp ├── 318A - Even Odds.cpp ├── 38A - Army.cpp ├── 168A - Wizards and Demonstration.cpp ├── 266A - Stones on the Table.cpp ├── 268C - Beautiful Sets of Points.cpp ├── 116A - Tram.cpp ├── 92A - Chips.cpp ├── 224A - Parallelepiped.cpp ├── 334A - Candy Bags.cpp ├── 104A - Blackjack.cpp ├── 165B - Burning Midnight Oil.py ├── 344A - Magnets.cpp ├── 46A - Ball Game.cpp ├── 322A - Ciel and Dancing.cpp ├── 231A - Team.cpp ├── 313A - Ilya and Bank Account.cpp ├── 279A - The Point on the Spiral.py ├── 246A - Buggy Sorting.cpp ├── 337B - Routine Problem.py ├── 41A - Translation.cpp ├── 270A - Fancy Fence.cpp ├── 81A - Plug-in.cpp ├── 228A - Is your horseshoe on the other hoof.cpp ├── 248A - Cupboards.cpp ├── 285A - Slightly Decreasing Permutations.cpp ├── 58B - Coins.cpp ├── 127B - Canvas Frames.cpp ├── 140A - New Year Table.cpp ├── 214A - System of Equations.cpp ├── 265B - Roadside Trees (Simplified Edition).cpp ├── 82A - Double Cola.cpp ├── 137B - Permutation.cpp ├── 332A - Down the Hatch!.cpp ├── 136A - Presents.cpp ├── 282A - Bit++.cpp ├── 339B - Xenia and Ringroad.cpp ├── 37A - Towers.cpp ├── 68A - Irrational problem.cpp ├── 129A - Cookies.cpp ├── 263A - Beautiful Matrix.cpp ├── 265A - Colorful Stones (Simplified Edition).cpp ├── 112A - Petya and Strings.cpp ├── 114A - Cifera.cpp ├── 233A - Perfect Permutation.cpp ├── 108A - Palindromic Times.cpp ├── 225A - Dice Tower.cpp ├── 245B - Internet Address.cpp ├── 236A - Boy or Girl.cpp ├── 263B - Squares.cpp ├── 71A - Way Too Long Words.cpp ├── 270B - Multithreading.cpp ├── 285B - Find Marble.cpp ├── 278A - Circle Line.cpp ├── 282B - Painting Eggs.cpp ├── 40A - Find Color.cpp ├── 61A - Ultra-Fast Mathematician.cpp ├── 272A - Dima and Friends.cpp ├── 336B - Vasily the Bear and Fly.cpp ├── 139A - Petr and Book.cpp ├── 271A - Beautiful Year.cpp ├── 34B - Sale.cpp ├── 11A - Increasing Sequence.cpp ├── 172A - Phone Code.cpp ├── 276B - Little Girl and Game.cpp ├── 285C - Building Permutation.cpp ├── 239A - Two Bags of Potatoes.cpp ├── 127A - Wasted Time.cpp ├── 194B - Square.cpp ├── 259A - Little Elephant and Chess.cpp ├── 110A - Nearly Lucky Number.cpp ├── 69A - Young Physicist.cpp ├── 118A - String Task.cpp ├── 262B - Roma and Changing Signs.py ├── 294A - Shaass and Oskols.cpp ├── 337A - Puzzles.cpp ├── 99A - Help Far Away Kingdom.cpp ├── 266B - Queue at the School.cpp ├── 25A - IQ test.cpp ├── 302B - Eugeny and Play List.cpp ├── 222A - Shooshuns and Sequence.cpp ├── 227B - Effective Approach.cpp ├── 315A - Sereja and Bottles.cpp ├── 131C - The World is a Theatre.cpp ├── 157B - Trace.cpp ├── 218A - Mountain Scenery.cpp ├── 23A - Youre Given a String.py ├── 322B - Ciel and Flowers.cpp ├── 80A - Panoramixs Prediction.cpp ├── 155A - I_love_%username%.cpp ├── 257A - Sockets.cpp ├── 137A - Postcards and photos.cpp ├── 158B - Taxi.cpp ├── 160A - Twins.cpp ├── 284B - Cows and Poker Game.cpp ├── 74A - Room Leader.cpp ├── 131B - Opposites Attract.cpp ├── 136B - Ternary Logic.cpp ├── 245A - System Administrator.cpp ├── 260A - Adding Digits.cpp ├── 35A - Shell Game.cpp ├── 237A - Free Cash.cpp ├── 252A - Little Xor.cpp ├── 255B - Code Parsing.cpp ├── 144A - Arrival of the General.cpp ├── 4C - Registration System.cpp ├── 106A - Card Game.cpp ├── 259B - Little Elephant and Magic Square.cpp ├── 26A - Almost Prime.cpp ├── 242B - Big Segment.cpp ├── 282C - XOR and OR.cpp ├── 302A - Eugeny and Array.cpp ├── 6A - Triangle.cpp ├── 146A - Lucky Ticket.cpp ├── 158A - Next Round.cpp ├── 268A - Games.cpp ├── 29A - Spit Problem.cpp ├── 313B - Ilya and Queries.cpp ├── 330B - Road Construction.cpp ├── 75A - Life Without Zeros.cpp ├── 96A - Football.cpp ├── 118B - Present from Lena.cpp ├── 262A - Roma and Lucky Numbers.cpp ├── 43A - Football.cpp ├── 94A - Restoring Password.cpp ├── 119A - Epic Game.cpp ├── 244A - Dividing Orange.cpp ├── 291A - Spyke Talks.cpp ├── 276A - Lunch Rush.cpp ├── 13A - Numbers.cpp ├── 327A - Flipping Game.cpp ├── 320A - Magic Numbers.cpp ├── 242A - Heads or Tails.cpp ├── 32A - Reconnaissance.cpp ├── 333B - Chips.cpp ├── 279B - Books.cpp ├── 318B - Strings of Power.cpp ├── 7A - Kalevitch and Chess.cpp ├── 149A - Business trip.cpp ├── 78A - Haiku.cpp ├── 116B - Little Pigs and Wolves.cpp ├── 298A - Snow Footprints.cpp ├── 205A - Little Elephant and Rozdil.cpp ├── 253A - Boys and Girls.cpp ├── 275A - Lights Out.cpp ├── 131A - cAPS lOCK.cpp ├── 16A - Flag.cpp ├── 106B - Choosing Laptop.cpp ├── 102B - Sum of Digits.cpp ├── 22A - Second Order Statistics.cpp ├── 34A - Reconnaissance 2.cpp ├── 58A - Chat room.cpp ├── 49A - Sleuth.cpp ├── 155B - Combination.cpp ├── 59A - Word.cpp ├── 141A - Amusing Joke.cpp ├── 296A - Yaroslav and Permutations.cpp ├── 315B - Sereja and Array.cpp ├── 66B - Petya and Countryside.cpp ├── 157A - Game Outcome.cpp ├── 17A - Noldbach problem.cpp ├── 336A - Vasily the Bear and Triangle.cpp ├── 330A - Cakeminator.cpp ├── 12B - Correct Solution.cpp ├── 276C - Little Girl and Maximum Sum.cpp ├── 3A - Shortest path of the king.cpp ├── 219A - k-String.cpp ├── 160B - Unlucky Ticket.cpp ├── 208D - Prizes, Prizes, more Prizes.cpp ├── 143A - Help Vasilisa the Wise 2.cpp ├── 208A - Dubstep.cpp ├── 255A - Greg's Workout.cpp ├── 215A - Bicycle Chain.cpp ├── 186A - Строкосравнитель.cpp ├── 122A - Lucky Division.cpp ├── 272B - Dima and Sequence.cpp ├── 264A - Escape from Stones.cpp ├── 342A - Xenia and Divisors.cpp ├── 337C - Quiz.cpp ├── 4B - Before an Exam.cpp ├── 230A - Dragons.cpp ├── 31A - Worms Evolution.cpp ├── 189A - Cut Ribbon.cpp ├── 203A - Two Problems.cpp ├── 161A - Dress'em in Vests!.cpp ├── 152A - Marks.cpp ├── 218B - Airport.cpp ├── 317A - Perfect Pair.cpp ├── 166A - Rank List.cpp ├── 287A - IQ Test.cpp ├── 230B - T-primes.cpp ├── 222B - Cosmic Tables.cpp ├── 133B - Unary.cpp ├── 221B - Little Elephant and Numbers.cpp ├── 334B - Eight Point Sets.cpp ├── 158D - Ice Sculptures.cpp ├── 298B - Sail.cpp ├── 316A1 - Special Task (30 points).cpp ├── 316A2 - Special Task (70 points).cpp ├── 63A - Sinking Ship.cpp ├── 79A - Bus Game.cpp ├── 236B - Easy Number Challenge.cpp ├── 271B - Prime Matrix.cpp ├── 165A - Supercentral Point.cpp ├── 317B - Ants.cpp ├── 278B - New Problem.cpp ├── 312A - Whose sentence is it.cpp ├── 148A - Insomnia cure.cpp ├── 291B - Command Line Arguments.cpp ├── 166E - Tetrahedron.cpp ├── 284A - Cows and Primitive Roots.cpp ├── 336C - Vasily the Bear and Sequence.cpp ├── 2A - Winner.cpp ├── 300A - Array.cpp ├── 1B - Spreadsheet.cpp ├── 335A - Banana.cpp ├── 159B - Matchmaker.cpp ├── 254A - Cards with Numbers.cpp ├── 158C - Cd and pwd commands.cpp └── 337E - Divisor Tree.cpp /README.md: -------------------------------------------------------------------------------- 1 | CodeForces 2 | ========== 3 | 4 | CodeForces 5 | -------------------------------------------------------------------------------- /110B - Lucky String.py: -------------------------------------------------------------------------------- 1 | #4314070 Aug 20, 2013 4:39:18 AM fuwutu 110B - Lucky String Python 3 Accepted 124 ms 0 KB 2 | n = int(input()) 3 | s = "abcd" * (n // 4) + "abcd"[0 : n % 4] 4 | print(s) 5 | -------------------------------------------------------------------------------- /195A - Let's Watch Football.cpp: -------------------------------------------------------------------------------- 1 | #4324702 Aug 22, 2013 7:41:39 PM fuwutu 195A - Let's Watch Football Python 3 Accepted 124 ms 0 KB 2 | l = input().split(' ') 3 | a, b, c = int(l[0]), int(l[1]), int(l[2]) 4 | d = ((a - b) * c + b - 1) // b 5 | print(d) 6 | -------------------------------------------------------------------------------- /327B - Hungry Sequence.py: -------------------------------------------------------------------------------- 1 | #4076363 Jul 15, 2013 7:24:55 PM fuwutu 327B - Hungry Sequence Python 3 Accepted 312 ms 100 KB 2 | import sys 3 | n = int(input()) 4 | sys.stdout.write(str(n)) 5 | for i in range(n+1, n*2): 6 | sys.stdout.write(" " + str(i)) 7 | -------------------------------------------------------------------------------- /182B - Vasya's Calendar.cpp: -------------------------------------------------------------------------------- 1 | #4314540 Aug 20, 2013 9:13:16 AM fuwutu 182B - Vasya's Calendar Python 3 Accepted 124 ms 0 KB 2 | d = int(input()) 3 | n = int(input()) 4 | l = input().split(' ') 5 | times = 0 6 | for i in range(0, n-1): 7 | times += d - int(l[i]) 8 | print(times) 9 | -------------------------------------------------------------------------------- /194A - Exams.cpp: -------------------------------------------------------------------------------- 1 | //4238316 Aug 7, 2013 4:47:59 AM fuwutu 194A - Exams GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | 4 | int main() 5 | { 6 | int n, k; 7 | scanf("%d%d", &n, &k); 8 | printf("%d\n", k <= n * 3 ? n * 3 - k : 0); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /84A - Toy Army.cpp: -------------------------------------------------------------------------------- 1 | //4033542 Jul 7, 2013 11:18:30 AM fuwutu 84A - Toy Army GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n; 9 | cin >> n; 10 | cout << n + n / 2 << endl; 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /199A - Hexadecimal's theorem.py: -------------------------------------------------------------------------------- 1 | #4055616 Jul 12, 2013 7:40:42 PM fuwutu 199A - Hexadecimal's theorem Python 3 Accepted 78 ms 100 KB 2 | n = int(input()) 3 | if n == 0: 4 | print(0, 0, 0) 5 | else: 6 | a, b = 0, 1 7 | while a + b != n: 8 | a, b = b, a + b 9 | print(0, a, b) 10 | -------------------------------------------------------------------------------- /50A - Domino piling.cpp: -------------------------------------------------------------------------------- 1 | //4006895 Jul 3, 2013 6:00:13 PM fuwutu 50A - Domino piling GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int M, N; 9 | cin >> M >> N; 10 | cout << M * N / 2 << endl; 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /47A - Triangular numbers.py: -------------------------------------------------------------------------------- 1 | #4266668 Aug 11, 2013 7:39:45 PM fuwutu 47A - Triangular numbers Python 3 Accepted 124 ms 0 KB 2 | n = int(input()) 3 | triangular = 1 4 | i = 1 5 | while triangular < n: 6 | i += 1 7 | triangular += i 8 | if triangular == n: 9 | print("YES") 10 | else: 11 | print("NO") 12 | -------------------------------------------------------------------------------- /124A - The number of positions.cpp: -------------------------------------------------------------------------------- 1 | //4032912 Jul 7, 2013 5:46:56 AM fuwutu 124A - The number of positions GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, a, b; 9 | cin >> n >> a >> b; 10 | cout << min(n - a, b + 1) << endl; 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /27A - Next Test.py: -------------------------------------------------------------------------------- 1 | #4271177 Aug 13, 2013 5:19:28 AM fuwutu 27A - Next Test Python 3 Accepted 124 ms 100 KB 2 | n = int(input()) 3 | s = set() 4 | while n != 0: 5 | for x in input().split(' '): 6 | s.add(int(x)) 7 | n -= 1 8 | for i in range(1, 3002): 9 | if not i in s: 10 | print(i) 11 | break 12 | -------------------------------------------------------------------------------- /4C - Registration System.py: -------------------------------------------------------------------------------- 1 | #4076779 Jul 15, 2013 8:58:49 PM fuwutu 4C - Registration System Python 3 Accepted 1828 ms 600 KB 2 | n = int(input()) 3 | d = {} 4 | for i in range(0, n): 5 | s = input() 6 | if s in d: 7 | print(s+str(d[s])) 8 | d[s] += 1 9 | else: 10 | print("OK") 11 | d[s] = 1 12 | -------------------------------------------------------------------------------- /216A - Tiling with Hexagons.cpp: -------------------------------------------------------------------------------- 1 | //4055814 Jul 12, 2013 8:45:32 PM fuwutu 216A - Tiling with Hexagons GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int a, b, c; 9 | cin >> a >> b >> c; 10 | cout << a * b + b * c + c * a - a - b - c + 1 << endl; 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /281A - Word Capitalization.cpp: -------------------------------------------------------------------------------- 1 | //4027326 Jul 5, 2013 6:20:12 PM fuwutu 281A - Word Capitalization GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | string s; 10 | cin >> s; 11 | s[0] = towupper(s[0]); 12 | cout << s << endl; 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /268B - Buttons.cpp: -------------------------------------------------------------------------------- 1 | //4027723 Jul 5, 2013 7:56:08 PM fuwutu 268B - Buttons GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | long long n; 9 | cin >> n; 10 | // 1*(n-1)+1 + 2*(n-2)+1 + 3*(n-3)+1 + ... + n*(n-n)+1 11 | cout << (n - 1) * n * (n + 1) / 6 + n << endl; 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /333A - Secrets.cpp: -------------------------------------------------------------------------------- 1 | //4188836 Jul 27, 2013 4:31:25 PM fuwutu 333A - Secrets GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | long long n; 9 | cin >> n; 10 | 11 | while (n % 3 == 0) 12 | { 13 | n /= 3; 14 | } 15 | 16 | cout << n / 3 + 1 << endl; 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /1A - Theater Square.cpp: -------------------------------------------------------------------------------- 1 | //4003927 Jul 2, 2013 8:12:30 PM fuwutu 1A - Theater Square GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | long long n, m, a, number; 9 | cin >> n >> m >> a; 10 | number = ((n + a - 1)) / a * ((m + a - 1) / a); 11 | cout << number << endl; 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /339A - Helpful Maths.py: -------------------------------------------------------------------------------- 1 | #4362738 Aug 28, 2013 6:54:41 PM fuwutu 339A - Helpful Maths Python 3 Accepted 92 ms 0 KB 2 | s = input() 3 | n1 = n2 = n3 = 0 4 | for i in range(0, len(s), 2): 5 | if s[i] == '1': 6 | n1 += 1 7 | elif s[i] == '2': 8 | n2 += 1 9 | else: 10 | n3 += 1 11 | ss = "1+" * n1 + "2+" * n2 + "3+" * n3 12 | print(ss[:-1]) 13 | -------------------------------------------------------------------------------- /151A - Soft Drinking.cpp: -------------------------------------------------------------------------------- 1 | //4033228 Jul 7, 2013 9:03:08 AM fuwutu 151A - Soft Drinking GNU C++0x Accepted 0 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, k, l, c, d, p, nl, np; 9 | cin >> n >> k >> l >> c >> d >> p >> nl >> np; 10 | cout << min(min(k * l / nl, c * d), p / np) / n << endl; 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /122B - Lucky Substring.py: -------------------------------------------------------------------------------- 1 | #4076744 Jul 15, 2013 8:50:51 PM fuwutu 122B - Lucky Substring Python 3 Accepted 62 ms 100 KB 2 | s = input() 3 | count4 = count7 = 0 4 | for c in s: 5 | if c == '4': 6 | count4 += 1 7 | elif c == '7': 8 | count7 += 1 9 | if count4 == 0 and count7 == 0: 10 | print(-1) 11 | elif count4 >= count7: 12 | print(4) 13 | else: 14 | print(7) 15 | -------------------------------------------------------------------------------- /257B - Playing Cubes.cpp: -------------------------------------------------------------------------------- 1 | //4266235 Aug 11, 2013 6:06:06 PM fuwutu 257B - Playing Cubes GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int n, m; 10 | cin >> n >> m; 11 | int Vasya = min(n, m); 12 | int Petya = n + m - 1 - Vasya; 13 | cout << Petya << " " << Vasya << endl; 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /340A - The Wall.py: -------------------------------------------------------------------------------- 1 | #4387236 Aug 31, 2013 3:00:19 PM fuwutu 340A - The Wall Python 3 Accepted 124 ms 0 KB 2 | def GCD(a, b): 3 | while a % b != 0: 4 | a, b = b, a % b 5 | return b 6 | 7 | def LCM(a, b): 8 | return a * b // GCD(a, b) 9 | 10 | l = input().split(' ') 11 | x, y, a, b = int(l[0]), int(l[1]), int(l[2]), int(l[3]) 12 | lcm = LCM(x, y) 13 | print(b // lcm - (a - 1) // lcm) 14 | -------------------------------------------------------------------------------- /4A - Watermelon.cpp: -------------------------------------------------------------------------------- 1 | //4003975 Jul 2, 2013 8:27:30 PM fuwutu 4A - Watermelon GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int w; 9 | cin >> w; 10 | if (w % 2 == 0 && w > 2) 11 | { 12 | cout << "YES" << endl; 13 | } 14 | else 15 | { 16 | cout << "NO" << endl; 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /221A - Little Elephant and Function.cpp: -------------------------------------------------------------------------------- 1 | //4033744 Jul 7, 2013 12:13:57 PM fuwutu 221A - Little Elephant and Function GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n; 9 | cin >> n; 10 | cout << n; 11 | for (int i = 1; i < n; ++i) 12 | { 13 | cout << " " << i; 14 | } 15 | cout << endl; 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /246B - Increase and Decrease.cpp: -------------------------------------------------------------------------------- 1 | //4058029 Jul 13, 2013 9:37:53 AM fuwutu 246B - Increase and Decrease GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | int main() 5 | { 6 | int n, a, sum(0); 7 | scanf("%d", &n); 8 | for (int i = 0; i < n; ++i) 9 | { 10 | scanf("%d", &a); 11 | sum += a; 12 | } 13 | printf("%d\n", sum % n == 0 ? n : n - 1); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /9A - Die Roll.cpp: -------------------------------------------------------------------------------- 1 | //4205051 Jul 30, 2013 7:59:44 PM fuwutu 9A - Die Roll GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int Y, W; 10 | cin >> Y >> W; 11 | 12 | const string probability[7] = {"", "1/1", "5/6", "2/3", "1/2", "1/3", "1/6"}; 13 | int D = max(Y, W); 14 | cout << probability[D] << endl; 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /289A - Polo the Penguin and Segments.cpp: -------------------------------------------------------------------------------- 1 | //4124774 Jul 21, 2013 4:09:28 AM fuwutu 289A - Polo the Penguin and Segments GNU C++0x Accepted 46 ms 0 KB 2 | #include 3 | 4 | int main() 5 | { 6 | int n, k, l, r, s(0); 7 | scanf("%d%d", &n, &k); 8 | while (n--) 9 | { 10 | scanf("%d%d", &l, &r); 11 | s = (s + r - l + 1) % k; 12 | } 13 | printf("%d\n", (k - s) % k); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /12A - Super Agent.cpp: -------------------------------------------------------------------------------- 1 | //4264533 Aug 11, 2013 11:29:23 AM fuwutu 12A - Super Agent GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | 4 | int main() 5 | { 6 | char symbols[3][4]; 7 | scanf("%s%s%s", symbols[0], symbols[1], symbols[2]); 8 | printf(symbols[0][0] == symbols[2][2] && symbols[0][1] == symbols[2][1] && symbols[0][2] == symbols[2][0] && symbols[1][0] == symbols[1][2] ? "YES\n" : "NO\n"); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /133A - HQ9+.cpp: -------------------------------------------------------------------------------- 1 | //4007157 Jul 3, 2013 7:19:37 PM fuwutu 133A - HQ9+ GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | string s; 10 | cin >> s; 11 | if (s.find_first_of("HQ9") != string::npos) 12 | { 13 | cout << "YES" << endl; 14 | } 15 | else 16 | { 17 | cout << "NO" << endl; 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /190A - Vasya and the Bus.cpp: -------------------------------------------------------------------------------- 1 | //4306482 Aug 18, 2013 7:22:51 AM fuwutu 190A - Vasya and the Bus GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | 4 | int main() 5 | { 6 | int n, m; 7 | scanf("%d%d", &n, &m); 8 | if (n != 0 || m == 0) 9 | { 10 | printf("%d %d\n", (m > n ? m : n), (m != 0 ? n + m - 1 : n)); 11 | } 12 | else 13 | { 14 | printf("Impossible\n"); 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /200B - Drinks.cpp: -------------------------------------------------------------------------------- 1 | //4033618 Jul 7, 2013 11:40:55 AM fuwutu 200B - Drinks GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, p, total(0); 9 | cin >> n; 10 | for (int i = 0; i < n; ++i) 11 | { 12 | cin >> p; 13 | total += p; 14 | } 15 | cout << static_cast(total) / static_cast(n) << endl; 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /318A - Even Odds.cpp: -------------------------------------------------------------------------------- 1 | //4034903 Jul 7, 2013 5:22:04 PM fuwutu 318A - Even Odds GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | long long n, k; 9 | cin >> n >> k; 10 | if (k <= (n + 1) / 2) 11 | { 12 | cout << k * 2 - 1 << endl; 13 | } 14 | else 15 | { 16 | cout << (k - (n + 1) / 2) * 2 << endl; 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /38A - Army.cpp: -------------------------------------------------------------------------------- 1 | //4035016 Jul 7, 2013 5:54:29 PM fuwutu 38A - Army GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int n, d[100] = {0}, a, b; 10 | cin >> n; 11 | for (int i = 1; i < n; ++i) 12 | { 13 | cin >> d[i]; 14 | } 15 | cin >> a >> b; 16 | cout << accumulate(d + a, d + b, 0) << endl; 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /168A - Wizards and Demonstration.cpp: -------------------------------------------------------------------------------- 1 | //4033567 Jul 7, 2013 11:26:18 AM fuwutu 168A - Wizards and Demonstration GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, x, y; 9 | cin >> n >> x >> y; 10 | int clones = (n * y + 99) / 100 - x; 11 | if (clones < 0) 12 | { 13 | clones = 0; 14 | } 15 | cout << clones << endl; 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /266A - Stones on the Table.cpp: -------------------------------------------------------------------------------- 1 | //4007012 Jul 3, 2013 6:39:25 PM fuwutu 266A - Stones on the Table GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | size_t n; 11 | cin >> n; 12 | string s; 13 | cin >> s; 14 | s.erase(unique(s.begin(), s.end()), s.end()); 15 | cout << n - s.length() << endl; 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /268C - Beautiful Sets of Points.cpp: -------------------------------------------------------------------------------- 1 | //4263502 Aug 11, 2013 6:01:01 AM fuwutu 268C - Beautiful Sets of Points GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | int n, m; 8 | scanf("%d%d", &n, &m); 9 | int k = std::min(n, m); 10 | printf("%d\n", k + 1); 11 | for (int i = 0; i <= k; ++i) 12 | { 13 | printf("%d %d\n", i, k - i); 14 | } 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /116A - Tram.cpp: -------------------------------------------------------------------------------- 1 | //4006879 Jul 3, 2013 5:53:08 PM fuwutu 116A - Tram GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | int main() 5 | { 6 | int n, a, b, c(0), m(0); 7 | scanf("%d", &n); 8 | while (n--) 9 | { 10 | scanf("%d%d", &a, &b); 11 | c -= a; 12 | c += b; 13 | if (c > m) 14 | { 15 | m = c; 16 | } 17 | } 18 | 19 | printf("%d\n", m); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /92A - Chips.cpp: -------------------------------------------------------------------------------- 1 | //4033461 Jul 7, 2013 10:48:16 AM fuwutu 92A - Chips GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, m; 9 | cin >> n >> m; 10 | m %= (n * (n + 1) / 2); 11 | for (int i = 1; i <= n; ++i) 12 | { 13 | if (m < i) 14 | { 15 | break; 16 | } 17 | m -= i; 18 | } 19 | cout << m << endl; 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /224A - Parallelepiped.cpp: -------------------------------------------------------------------------------- 1 | //4033775 Jul 7, 2013 12:22:12 PM fuwutu 224A - Parallelepiped GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int ab, bc, ca; 10 | cin >> ab >> bc >> ca; 11 | int a = sqrt(ab * ca / bc + 0.5); 12 | int b = sqrt(bc * ab / ca + 0.5); 13 | int c = sqrt(ca * bc / ab + 0.5); 14 | cout << (a + b + c) * 4 << endl; 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /334A - Candy Bags.cpp: -------------------------------------------------------------------------------- 1 | //4175632 Jul 27, 2013 12:40:22 PM fuwutu 334A - Candy Bags GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | 4 | int main() 5 | { 6 | int n; 7 | scanf("%d", &n); 8 | for (int i = 0; i < n; ++i) 9 | { 10 | printf("%d", i + 1); 11 | for (int j = 1; j < n; ++j) 12 | { 13 | printf(" %d", n * j + (i + j) % n + 1); 14 | } 15 | printf("\n"); 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /104A - Blackjack.cpp: -------------------------------------------------------------------------------- 1 | //4055407 Jul 12, 2013 6:41:00 PM fuwutu 104A - Blackjack GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n; 9 | cin >> n; 10 | if (n <= 10 || n > 21) 11 | { 12 | cout << 0 << endl; 13 | } 14 | else if (n == 20) 15 | { 16 | cout << 15 << endl; 17 | } 18 | else 19 | { 20 | cout << 4 << endl; 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /165B - Burning Midnight Oil.py: -------------------------------------------------------------------------------- 1 | #4314087 Aug 20, 2013 4:53:51 AM fuwutu 165B - Burning Midnight Oil Python 3 Accepted 124 ms 0 KB 2 | l = input().split(' ') 3 | n, k = int(l[0]), int(l[1]) 4 | left, right = 1, n 5 | while left != right: 6 | x = middle = (left + right) // 2 7 | sum = 0 8 | while x != 0: 9 | sum += x 10 | x //= k 11 | if sum >= n: 12 | right = middle 13 | else: 14 | left = middle + 1 15 | print(left) 16 | -------------------------------------------------------------------------------- /344A - Magnets.cpp: -------------------------------------------------------------------------------- 1 | //4592799 Sep 28, 2013 4:08:58 AM fuwutu 344A - Magnets GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | 4 | int main() 5 | { 6 | int n, groups(0); 7 | scanf("%d", &n); 8 | 9 | char s[3], c('\0'); 10 | while (n--) 11 | { 12 | scanf("%s", s); 13 | if (s[0] != c) 14 | { 15 | groups += 1; 16 | } 17 | c = s[0]; 18 | } 19 | 20 | printf("%d\n",groups); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /46A - Ball Game.cpp: -------------------------------------------------------------------------------- 1 | //4136831 Jul 22, 2013 9:10:08 PM fuwutu 46A - Ball Game GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, c(2); 9 | cin >> n; 10 | cout << c; 11 | for (int i = 2; i < n; ++i) 12 | { 13 | c += i; 14 | if (c > n) 15 | { 16 | c -= n; 17 | } 18 | cout << " " << c; 19 | } 20 | cout << endl; 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /322A - Ciel and Dancing.cpp: -------------------------------------------------------------------------------- 1 | //4058132 Jul 13, 2013 10:10:07 AM fuwutu 322A - Ciel and Dancing GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, m; 9 | cin >> n >> m; 10 | cout << n + m - 1 << endl; 11 | for (int i = 1; i <= m; ++i) 12 | { 13 | cout << "1 " << i << endl; 14 | } 15 | for (int i = 2; i <= n; ++i) 16 | { 17 | cout << i << " 1" << endl; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /231A - Team.cpp: -------------------------------------------------------------------------------- 1 | //4006945 Jul 3, 2013 6:18:52 PM fuwutu 231A - Team GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, Petya, Vasya, Tonya, number(0); 9 | cin >> n; 10 | while (n--) 11 | { 12 | cin >> Petya >> Vasya >> Tonya; 13 | if (Petya + Vasya + Tonya >= 2) 14 | { 15 | number += 1; 16 | } 17 | } 18 | cout << number << endl; 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /313A - Ilya and Bank Account.cpp: -------------------------------------------------------------------------------- 1 | //4033204 Jul 7, 2013 8:52:56 AM fuwutu 313A - Ilya and Bank Account GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n; 9 | cin >> n; 10 | if (n >= 0) 11 | { 12 | cout << n << endl; 13 | } 14 | else 15 | { 16 | int a = n / 10; 17 | int b = n / 100 * 10 + n % 10; 18 | cout << max(a, b) << endl; 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /279A - The Point on the Spiral.py: -------------------------------------------------------------------------------- 1 | #4304263 Aug 17, 2013 7:17:58 PM fuwutu 279A - The Point on the Spiral Python 3 Accepted 124 ms 0 KB 2 | l = input().split(' ') 3 | x, y = int(l[0]), int(l[1]) 4 | if y <= 0 and x >= 1 + y and x <= 1 - y: 5 | print((-y) * 4) 6 | elif x > 0 and y >= 2 - x and y <= x: 7 | print(x * 4 - 3) 8 | elif y > 0 and x >= -y and x <= y - 1: 9 | print(y * 4 - 2) 10 | elif x < 0 and y >= x and y <= -1 - x: 11 | print((-x) * 4 - 1) 12 | else: 13 | print(0) 14 | -------------------------------------------------------------------------------- /246A - Buggy Sorting.cpp: -------------------------------------------------------------------------------- 1 | //4033438 Jul 7, 2013 10:40:48 AM fuwutu 246A - Buggy Sorting GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n; 9 | cin >> n; 10 | if (n > 2) 11 | { 12 | for (int i = 2; i <= n; ++i) 13 | { 14 | cout << i << " "; 15 | } 16 | cout << 1 << endl; 17 | } 18 | else 19 | { 20 | cout << -1 << endl; 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /337B - Routine Problem.py: -------------------------------------------------------------------------------- 1 | #4302271 Aug 17, 2013 12:41:50 PM fuwutu 337B - Routine Problem Python 3 Accepted 92 ms 0 KB 2 | def gcd(a, b): 3 | while a % b != 0: 4 | a, b = b, a % b 5 | return b 6 | 7 | l = input().split(' ') 8 | a, b, c, d = int(l[0]), int(l[1]), int(l[2]), int(l[3]) 9 | if a * d > b * c: 10 | p = a * d - b * c 11 | q = a * d 12 | else: 13 | p = b * c - a * d 14 | q = b * c 15 | e = gcd(p, q) 16 | p //= e 17 | q //= e 18 | print(str(p) + "/" + str(q)) 19 | -------------------------------------------------------------------------------- /41A - Translation.cpp: -------------------------------------------------------------------------------- 1 | //4032948 Jul 7, 2013 6:21:47 AM fuwutu 41A - Translation GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | string s, t; 11 | cin >> s >> t; 12 | reverse(t.begin(), t.end()); 13 | if (s == t) 14 | { 15 | cout << "YES" << endl; 16 | } 17 | else 18 | { 19 | cout << "NO" << endl; 20 | } 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /270A - Fancy Fence.cpp: -------------------------------------------------------------------------------- 1 | //4032932 Jul 7, 2013 6:02:15 AM fuwutu 270A - Fancy Fence GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int t, a; 9 | cin >> t; 10 | while (t--) 11 | { 12 | cin >> a; 13 | if (360 % (180 - a) == 0) 14 | { 15 | cout << "YES" << endl; 16 | } 17 | else 18 | { 19 | cout << "NO" << endl; 20 | } 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /81A - Plug-in.cpp: -------------------------------------------------------------------------------- 1 | //4055785 Jul 12, 2013 8:36:40 PM fuwutu 81A - Plug-in GNU C++0x Accepted 15 ms 200 KB 2 | #include 3 | 4 | int main() 5 | { 6 | char ch[200001]; 7 | scanf("%s", ch); 8 | char* p = ch; 9 | int n = 0; 10 | while (*p != 0) 11 | { 12 | ch[n++] = *p; 13 | if (n >= 2 && ch[n-1] == ch[n-2]) 14 | { 15 | n -= 2; 16 | } 17 | ++p; 18 | } 19 | ch[n] = 0; 20 | printf("%s\n", ch); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /228A - Is your horseshoe on the other hoof.cpp: -------------------------------------------------------------------------------- 1 | //4021166 Jul 4, 2013 7:14:46 PM fuwutu 228A - Is your horseshoe on the other hoof? GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | vector s(4); 11 | cin >> s[0] >> s[1] >> s[2] >> s[3]; 12 | sort(s.begin(), s.end()); 13 | s.erase(unique(s.begin(), s.end()), s.end()); 14 | cout << 4 - s.size() << endl; 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /248A - Cupboards.cpp: -------------------------------------------------------------------------------- 1 | //4034999 Jul 7, 2013 5:49:19 PM fuwutu 248A - Cupboards GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int n, l, r, left(0), right(0); 10 | scanf("%d", &n); 11 | for (int i = 0; i < n; ++i) 12 | { 13 | scanf("%d%d", &l, &r); 14 | left += l; 15 | right += r; 16 | } 17 | printf("%d\n", min(left, n - left) + min(right, n - right)); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /285A - Slightly Decreasing Permutations.cpp: -------------------------------------------------------------------------------- 1 | //4033063 Jul 7, 2013 7:36:19 AM fuwutu 285A - Slightly Decreasing Permutations GNU C++0x Accepted 31 ms 0 KB 2 | #include 3 | 4 | int main() 5 | { 6 | int n, k; 7 | scanf("%d%d", &n, &k); 8 | 9 | for (int i = 0; i < k; ++i) 10 | { 11 | printf("%d ", n - i); 12 | } 13 | printf("1"); 14 | for (int i = 2; i <= n - k; ++i) 15 | { 16 | printf(" %d", i); 17 | } 18 | printf("\n"); 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /58B - Coins.cpp: -------------------------------------------------------------------------------- 1 | //4240179 Aug 7, 2013 4:19:54 PM fuwutu 58B - Coins GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | 4 | int main() 5 | { 6 | int n; 7 | scanf("%d", &n); 8 | while (n != 1) 9 | { 10 | printf("%d ", n); 11 | for (int i = 2; i <= n; ++i) 12 | { 13 | if (n % i == 0) 14 | { 15 | n /= i; 16 | break; 17 | } 18 | } 19 | } 20 | printf("%d\n", n); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /127B - Canvas Frames.cpp: -------------------------------------------------------------------------------- 1 | //4035363 Jul 7, 2013 7:45:38 PM fuwutu 127B - Canvas Frames GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, a, count[101] = {0}; 9 | cin >> n; 10 | while (n--) 11 | { 12 | cin >> a; 13 | count[a] += 1; 14 | } 15 | int total = 0; 16 | for (int i = 1; i <= 100; ++i) 17 | { 18 | total += count[i] / 2; 19 | } 20 | cout << total / 2 << endl; 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /140A - New Year Table.cpp: -------------------------------------------------------------------------------- 1 | //4236895 Aug 6, 2013 4:35:30 PM fuwutu 140A - New Year Table GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | int n; 8 | double R, r; 9 | scanf("%d%lf%lf", &n, &R, &r); 10 | if ( n == 1 && r <= R 11 | || n == 2 && r * 2 <= R 12 | || asin(r / (R - r)) * n <= 3.1415927) 13 | { 14 | printf("YES\n"); 15 | } 16 | else 17 | { 18 | printf("NO\n"); 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /214A - System of Equations.cpp: -------------------------------------------------------------------------------- 1 | //4032999 Jul 7, 2013 7:05:20 AM fuwutu 214A - System of Equations GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, m, answer(0); 9 | cin >> n >> m; 10 | 11 | for (int a = 0; a * a <= n && a <= m; ++a) 12 | { 13 | int b = n - a * a; 14 | if (a + b * b == m) 15 | { 16 | answer += 1; 17 | } 18 | } 19 | 20 | cout << answer << endl; 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /265B - Roadside Trees (Simplified Edition).cpp: -------------------------------------------------------------------------------- 1 | //4035298 Jul 7, 2013 7:23:30 PM fuwutu 265B - Roadside Trees (Simplified Edition) GNU C++0x Accepted 31 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int n, h, h0(0); 10 | scanf("%d", &n); 11 | int time = n + n - 1; 12 | while (n--) 13 | { 14 | scanf("%d", &h); 15 | time += abs(h - h0); 16 | h0 = h; 17 | } 18 | printf("%d\n", time); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /82A - Double Cola.cpp: -------------------------------------------------------------------------------- 1 | //4006861 Jul 3, 2013 5:47:02 PM fuwutu 82A - Double Cola GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int n; 10 | cin >> n; 11 | 12 | int r = 1; 13 | while (r * 5 < n) 14 | { 15 | n -= r * 5; 16 | r *= 2; 17 | } 18 | 19 | string names[] = {"Sheldon", "Leonard", "Penny", "Rajesh", "Howard"}; 20 | cout << names[(n - 1) / r] << endl; 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /137B - Permutation.cpp: -------------------------------------------------------------------------------- 1 | //4055758 Jul 12, 2013 8:25:21 PM fuwutu 137B - Permutation GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int n, a, appear[5001] = {0}; 10 | cin >> n; 11 | 12 | for (int i = 0; i < n; ++i) 13 | { 14 | cin >> a; 15 | if (a <= n) 16 | { 17 | appear[a] = 1; 18 | } 19 | } 20 | cout << count(appear + 1, appear + n + 1, 0) << endl; 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /332A - Down the Hatch!.cpp: -------------------------------------------------------------------------------- 1 | //4236727 Aug 6, 2013 3:44:49 PM fuwutu 332A - Down the Hatch! GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int n, glasses(0); 10 | string s; 11 | cin >> n >> s; 12 | for (int i = n; i < s.length(); i += n) 13 | { 14 | if (s[i-1] == s[i-2] && s[i-2] == s[i-3]) 15 | { 16 | ++glasses; 17 | } 18 | } 19 | cout << glasses << endl; 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /136A - Presents.cpp: -------------------------------------------------------------------------------- 1 | //4021420 Jul 4, 2013 7:30:15 PM fuwutu 136A - Presents GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int n, p; 10 | cin >> n; 11 | vector f(n+1); 12 | for (int i = 1; i <= n; ++i) 13 | { 14 | cin >> p; 15 | f[p] = i; 16 | } 17 | cout << f[1]; 18 | for (int i = 2; i <= n; ++i) 19 | { 20 | cout << " " << f[i]; 21 | } 22 | cout << endl; 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /282A - Bit++.cpp: -------------------------------------------------------------------------------- 1 | //4007122 Jul 3, 2013 7:08:49 PM fuwutu 282A - Bit++ GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int n, x(0); 10 | cin >> n; 11 | 12 | string s; 13 | while (n--) 14 | { 15 | cin >> s; 16 | if (s[1] == '+') 17 | { 18 | ++x; 19 | } 20 | else 21 | { 22 | --x; 23 | } 24 | } 25 | 26 | cout << x << endl; 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /339B - Xenia and Ringroad.cpp: -------------------------------------------------------------------------------- 1 | //4362875 Aug 28, 2013 7:34:17 PM fuwutu 339B - Xenia and Ringroad GNU C++0x Accepted 62 ms 0 KB 2 | #include 3 | 4 | int main() 5 | { 6 | int n, m, a0, a, cycle = 0; 7 | scanf("%d%d%d", &n, &m, &a0); 8 | while (--m) 9 | { 10 | scanf("%d", &a); 11 | if (a0 > a) 12 | { 13 | cycle += 1; 14 | } 15 | a0 = a; 16 | } 17 | printf("%I64d\n", static_cast(n) * static_cast(cycle) + a0 - 1); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /37A - Towers.cpp: -------------------------------------------------------------------------------- 1 | //4033020 Jul 7, 2013 7:13:59 AM fuwutu 37A - Towers GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int n, l, h[1001] = {0}; 10 | cin >> n; 11 | while (n--) 12 | { 13 | cin >> l; 14 | h[l] += 1; 15 | } 16 | 17 | int height = *max_element(h, h + 1001); 18 | int number = 1001 - count(h, h + 1001, 0); 19 | 20 | cout << height << " " << number << endl; 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /68A - Irrational problem.cpp: -------------------------------------------------------------------------------- 1 | //4205110 Jul 30, 2013 8:14:07 PM fuwutu 68A - Irrational problem GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int p[4], a, b; 10 | cin >> p[0] >> p[1] >> p[2] >> p[3] >> a >> b; 11 | 12 | int m = *min_element(p, p + 4); 13 | if (a < m) 14 | { 15 | cout << min(b, m - 1) - a + 1 << endl; 16 | } 17 | else 18 | { 19 | cout << 0 << endl; 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /129A - Cookies.cpp: -------------------------------------------------------------------------------- 1 | //4033714 Jul 7, 2013 12:04:07 PM fuwutu 129A - Cookies GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, a, odd(0), even(0); 9 | cin >> n; 10 | while (n--) 11 | { 12 | cin >> a; 13 | if (a % 2 == 0) 14 | { 15 | even += 1; 16 | } 17 | else 18 | { 19 | odd += 1; 20 | } 21 | } 22 | 23 | cout << (odd % 2 == 1 ? odd : even) << endl; 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /263A - Beautiful Matrix.cpp: -------------------------------------------------------------------------------- 1 | //4027348 Jul 5, 2013 6:26:08 PM fuwutu 263A - Beautiful Matrix GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int x = 0; 10 | for (int i = 1; i <= 5; ++i) 11 | { 12 | for (int j = 1; j <= 5; ++j) 13 | { 14 | cin >> x; 15 | if (x == 1) 16 | { 17 | cout << abs(i - 3) + abs(j - 3) << endl; 18 | } 19 | } 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /265A - Colorful Stones (Simplified Edition).cpp: -------------------------------------------------------------------------------- 1 | //4033637 Jul 7, 2013 11:44:53 AM fuwutu 265A - Colorful Stones (Simplified Edition) GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | string s, t; 10 | cin >> s >> t; 11 | size_t pos = 0; 12 | for (size_t i = 0; i < t.length(); ++i) 13 | { 14 | if (t[i] == s[pos]) 15 | { 16 | pos += 1; 17 | } 18 | } 19 | cout << pos + 1 << endl; 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /112A - Petya and Strings.cpp: -------------------------------------------------------------------------------- 1 | //4006999 Jul 3, 2013 6:34:23 PM fuwutu 112A - Petya and Strings GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | int main() 11 | { 12 | string s1, s2; 13 | cin >> s1 >> s2; 14 | transform(s1.begin(), s1.end(), s1.begin(), ::tolower); 15 | transform(s2.begin(), s2.end(), s2.begin(), ::tolower); 16 | cout << strcmp(s1.c_str(), s2.c_str()) << endl; 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /114A - Cifera.cpp: -------------------------------------------------------------------------------- 1 | //4033910 Jul 7, 2013 12:48:27 PM fuwutu 114A - Cifera GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int k, l, importance(-1); 9 | cin >> k >> l; 10 | while (l % k == 0) 11 | { 12 | l /= k; 13 | importance += 1; 14 | } 15 | if (importance >= 0 && l == 1) 16 | { 17 | cout << "YES" << endl << importance << endl; 18 | } 19 | else 20 | { 21 | cout << "NO" << endl; 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /233A - Perfect Permutation.cpp: -------------------------------------------------------------------------------- 1 | //4033107 Jul 7, 2013 8:03:16 AM fuwutu 233A - Perfect Permutation GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n; 9 | cin >> n; 10 | if (n % 2 == 1) 11 | { 12 | cout << -1 << endl; 13 | } 14 | else 15 | { 16 | cout << "2 1"; 17 | for (int i = 3; i < n; i += 2) 18 | { 19 | cout << " " << i + 1 << " " << i; 20 | } 21 | cout << endl; 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /108A - Palindromic Times.cpp: -------------------------------------------------------------------------------- 1 | //4240194 Aug 7, 2013 4:26:51 PM fuwutu 108A - Palindromic Times GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | 4 | int main() 5 | { 6 | int hh, mm; 7 | scanf("%d:%d", &hh, &mm); 8 | do 9 | { 10 | ++mm; 11 | if (mm == 60) 12 | { 13 | ++hh; 14 | mm = 0; 15 | } 16 | if (hh == 24) 17 | { 18 | hh = 0; 19 | } 20 | } while (hh % 10 * 10 + hh / 10 != mm); 21 | printf("%02d:%02d\n", hh, mm); 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /225A - Dice Tower.cpp: -------------------------------------------------------------------------------- 1 | //4042654 Jul 9, 2013 5:40:32 PM fuwutu 225A - Dice Tower GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | bool possible(true); 9 | int n, x, a, b; 10 | cin >> n >> x; 11 | while (n--) 12 | { 13 | cin >> a >> b; 14 | if (x == a || x == b || x == 7 - a || x == 7 - b) 15 | { 16 | possible = false; 17 | } 18 | x = 7 - x; 19 | } 20 | cout << (possible ? "YES" : "NO") << endl; 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /245B - Internet Address.cpp: -------------------------------------------------------------------------------- 1 | //4263640 Aug 11, 2013 6:44:25 AM fuwutu 245B - Internet Address GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | string s; 10 | cin >> s; 11 | 12 | size_t p = s.find('p'); 13 | s.insert(p + 1, "://"); 14 | 15 | size_t ru = s.find("ru", p + 5); 16 | if (ru + 2 != s.length()) 17 | { 18 | s.insert(ru + 2, "/"); 19 | } 20 | s.insert(ru, "."); 21 | 22 | cout << s << endl; 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /236A - Boy or Girl.cpp: -------------------------------------------------------------------------------- 1 | //4022081 Jul 4, 2013 8:27:39 PM fuwutu 236A - Boy or Girl GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | string s; 11 | cin >> s; 12 | sort(s.begin(), s.end()); 13 | s.erase(unique(s.begin(), s.end()), s.end()); 14 | if (s.length() % 2 == 0) 15 | { 16 | cout << "CHAT WITH HER!" << endl; 17 | } 18 | else 19 | { 20 | cout << "IGNORE HIM!" << endl; 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /263B - Squares.cpp: -------------------------------------------------------------------------------- 1 | //4033603 Jul 7, 2013 11:36:30 AM fuwutu 263B - Squares GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int n, k, a[50+1]; 10 | cin >> n >> k; 11 | for (int i = 0; i < n; ++i) 12 | cin >> a[i]; 13 | sort(a, a + n, greater()); 14 | a[n] = 0; 15 | if (k > n) 16 | { 17 | cout << -1 << endl; 18 | } 19 | else 20 | { 21 | cout << a[k-1] << " " << 0 << endl; 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /71A - Way Too Long Words.cpp: -------------------------------------------------------------------------------- 1 | //4004040 Jul 2, 2013 8:47:17 PM fuwutu 71A - Way Too Long Words GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n; 9 | string s; 10 | cin >> n; 11 | while (n--) 12 | { 13 | cin >> s; 14 | if (s.length() > 10) 15 | { 16 | cout << s[0] << s.length() - 2 << s[s.length() - 1] << endl; 17 | } 18 | else 19 | { 20 | cout << s << endl; 21 | } 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /270B - Multithreading.cpp: -------------------------------------------------------------------------------- 1 | //4189214 Jul 27, 2013 5:01:04 PM fuwutu 270B - Multithreading GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | 4 | int main() 5 | { 6 | int n, a0, a, ascending(1); 7 | scanf("%d%d", &n, &a0); 8 | for (int i = 1; i < n; ++i) 9 | { 10 | scanf("%d", &a); 11 | if (a > a0) 12 | { 13 | ascending += 1; 14 | } 15 | else 16 | { 17 | ascending = 1; 18 | } 19 | a0 = a; 20 | } 21 | printf("%d\n", n - ascending); 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /285B - Find Marble.cpp: -------------------------------------------------------------------------------- 1 | //4035044 Jul 7, 2013 6:06:34 PM fuwutu 285B - Find Marble GNU C++0x Accepted 46 ms 400 KB 2 | #include 3 | 4 | int main() 5 | { 6 | int n, s, t, p[100000+1]; 7 | scanf("%d%d%d", &n, &s, &t); 8 | for (int i = 1; i <= n; ++i) 9 | { 10 | scanf("%d", &p[i]); 11 | } 12 | int step = 0; 13 | while (s != t && p[s] != 0) 14 | { 15 | int temp = p[s]; 16 | p[s] = 0; 17 | s = temp; 18 | step += 1; 19 | } 20 | printf("%d\n", s == t ? step : -1); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /278A - Circle Line.cpp: -------------------------------------------------------------------------------- 1 | //4032921 Jul 7, 2013 5:54:54 AM fuwutu 278A - Circle Line GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, d, f[100+2] = {0}, s, t; 9 | cin >> n; 10 | for (int i = 2; i < n + 2; ++i) 11 | { 12 | cin >> d; 13 | f[i] = f[i-1] + d; 14 | } 15 | cin >> s >> t; 16 | if (s > t) 17 | { 18 | swap(s, t); 19 | } 20 | int distance = f[t] - f[s]; 21 | cout << min(distance, (f[n+1] - distance)) << endl; 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /282B - Painting Eggs.cpp: -------------------------------------------------------------------------------- 1 | //4058602 Jul 13, 2013 12:18:22 PM fuwutu 282B - Painting Eggs GNU C++0x Accepted 484 ms 0 KB 2 | #include 3 | 4 | int main() 5 | { 6 | int n, a, g; 7 | scanf("%d", &n); 8 | 9 | int A(0); 10 | while (n--) 11 | { 12 | scanf("%d%d", &a, &g); 13 | A += a; 14 | if (A <= 500) 15 | { 16 | printf("A"); 17 | } 18 | else 19 | { 20 | A -= 1000; 21 | printf("G"); 22 | } 23 | } 24 | printf("\n"); 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /40A - Find Color.cpp: -------------------------------------------------------------------------------- 1 | //4265426 Aug 11, 2013 3:03:02 PM fuwutu 40A - Find Color GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | int x, y; 8 | scanf("%d%d", &x, &y); 9 | int r2 = x * x + y * y; 10 | int r = floor(sqrt(static_cast(r2))); 11 | if (r * r < r2 && (r + 1) * (r + 1) > r2 12 | && (r % 2 == 1 && x * y > 0 || r % 2 == 0 && x * y < 0)) 13 | { 14 | printf("white\n"); 15 | } 16 | else 17 | { 18 | printf("black\n"); 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /61A - Ultra-Fast Mathematician.cpp: -------------------------------------------------------------------------------- 1 | //4027387 Jul 5, 2013 6:31:42 PM fuwutu 61A - Ultra-Fast Mathematician GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | string s1, s2; 10 | cin >> s1 >> s2; 11 | for (size_t i = 0; i < s1.length(); ++i) 12 | { 13 | if (s1[i] == s2[i]) 14 | { 15 | s1[i] = '0'; 16 | } 17 | else 18 | { 19 | s1[i] = '1'; 20 | } 21 | } 22 | cout << s1 << endl; 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /272A - Dima and Friends.cpp: -------------------------------------------------------------------------------- 1 | //4033146 Jul 7, 2013 8:27:46 AM fuwutu 272A - Dima and Friends GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, f, total(0), answer(0); 9 | cin >> n; 10 | for (int i = 0; i < n; ++i) 11 | { 12 | cin >> f; 13 | total += f; 14 | } 15 | for (int i = 1; i <= 5; ++i) 16 | { 17 | if ((total + i) % (n + 1) != 1) 18 | { 19 | answer += 1; 20 | } 21 | } 22 | cout << answer << endl; 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /336B - Vasily the Bear and Fly.cpp: -------------------------------------------------------------------------------- 1 | //4262082 Aug 10, 2013 7:07:20 PM fuwutu 336B - Vasily the Bear and Fly GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | double m, R; 11 | cin >> m >> R; 12 | 13 | double answer = (m * (m + 1) * (m + 2) / 3 - m) * 2; 14 | answer += (sqrt(2.0) - 2) * ((m * m - m) + (m * m - m - (m - 1) * 2)); 15 | answer /= (m * m); 16 | 17 | answer *= R; 18 | cout << setprecision(7) << answer << endl; 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /139A - Petr and Book.cpp: -------------------------------------------------------------------------------- 1 | //4034061 Jul 7, 2013 1:27:10 PM fuwutu 139A - Petr and Book GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, y[8] = {0}; 9 | cin >> n; 10 | for (int d = 1; d <= 7; ++d) 11 | { 12 | cin >> y[d]; 13 | y[d] += y[d-1]; 14 | } 15 | n = (n - 1) % y[7] + 1; 16 | for (int d = 1; d <= 7; ++d) 17 | { 18 | if (y[d] >= n) 19 | { 20 | cout << d << endl; 21 | break; 22 | } 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /271A - Beautiful Year.cpp: -------------------------------------------------------------------------------- 1 | //4022146 Jul 4, 2013 8:34:23 PM fuwutu 271A - Beautiful Year GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int y; 9 | cin >> y; 10 | while (true) 11 | { 12 | y += 1; 13 | int a = y / 1000; 14 | int b = y / 100 % 10; 15 | int c = y / 10 % 10; 16 | int d = y % 10; 17 | if (a != b && a != c && a != d && b != c && b != d && c != d) 18 | { 19 | break; 20 | } 21 | } 22 | cout << y << endl; 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /34B - Sale.cpp: -------------------------------------------------------------------------------- 1 | //4263357 Aug 11, 2013 5:15:57 AM fuwutu 34B - Sale GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int n, m, a[100]; 10 | cin >> n >> m; 11 | for (int i = 0; i < n; ++i) 12 | { 13 | cin >> a[i]; 14 | } 15 | sort(a, a + n); 16 | 17 | int s(0); 18 | for (int i = 0; i < m; ++i) 19 | { 20 | if (a[i] >= 0) 21 | { 22 | break; 23 | } 24 | s += a[i]; 25 | } 26 | cout << -s << endl; 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /11A - Increasing Sequence.cpp: -------------------------------------------------------------------------------- 1 | //4264920 Aug 11, 2013 12:53:46 PM fuwutu 11A - Increasing Sequence GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | 4 | int main() 5 | { 6 | int n, d, b0, b, moves(0); 7 | scanf("%d%d%d", &n, &d, &b0); 8 | while (--n) 9 | { 10 | scanf("%d", &b); 11 | if (b <= b0) 12 | { 13 | int x = (b0 - b) / d + 1; 14 | moves += x; 15 | b0 = b + x * d; 16 | } 17 | else 18 | { 19 | b0 = b; 20 | } 21 | } 22 | printf("%d\n", moves); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /172A - Phone Code.cpp: -------------------------------------------------------------------------------- 1 | //4059111 Jul 13, 2013 2:09:39 PM fuwutu 172A - Phone Code GNU C++0x Accepted 31 ms 0 KB 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | int n; 8 | char s0[21], s[21]; 9 | scanf("%d%s", &n, s0); 10 | int m = strlen(s0); 11 | while (--n) 12 | { 13 | scanf("%s", s); 14 | for (int i = 0; i < m; ++i) 15 | { 16 | if (s[i] != s0[i]) 17 | { 18 | m = i; 19 | break; 20 | } 21 | } 22 | } 23 | printf("%d\n", m); 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /276B - Little Girl and Game.cpp: -------------------------------------------------------------------------------- 1 | //4057570 Jul 13, 2013 7:06:56 AM fuwutu 276B - Little Girl and Game GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | string s; 10 | cin >> s; 11 | 12 | bool odd[26] = {false}; 13 | for (size_t i = 0; i < s.length(); ++i) 14 | { 15 | odd[s[i]-'a'] = !odd[s[i]-'a']; 16 | } 17 | int oddcount = count(odd, odd + sizeof(odd) / sizeof(odd[0]), true); 18 | cout << (oddcount == 0 || oddcount % 2 == 1 ? "First" : "Second") << endl; 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /285C - Building Permutation.cpp: -------------------------------------------------------------------------------- 1 | //4034133 Jul 7, 2013 1:47:35 PM fuwutu 285C - Building Permutation GNU C++0x Accepted 140 ms 1100 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int n, a[300000]; 10 | scanf("%d", &n); 11 | 12 | for (int i = 0; i < n; ++i) 13 | { 14 | scanf("%d", &a[i]); 15 | } 16 | sort(a, a + n); 17 | 18 | long long result(0); 19 | for (int i = 0; i < n; ++i) 20 | { 21 | result += abs(i + 1 - a[i]); 22 | } 23 | printf("%I64d", result); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /239A - Two Bags of Potatoes.cpp: -------------------------------------------------------------------------------- 1 | //4057974 Jul 13, 2013 9:21:57 AM fuwutu 239A - Two Bags of Potatoes GNU C++0x Accepted 62 ms 0 KB 2 | #include 3 | 4 | int main() 5 | { 6 | int y, k, n; 7 | scanf("%d%d%d", &y, &k, &n); 8 | int x = k - y % k; 9 | int top = n - y; 10 | if (x <= top) 11 | { 12 | printf("%d", x); 13 | x += k; 14 | while (x <= top) 15 | { 16 | printf(" %d", x); 17 | x += k; 18 | } 19 | printf("\n"); 20 | } 21 | else 22 | { 23 | printf("-1\n"); 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /127A - Wasted Time.cpp: -------------------------------------------------------------------------------- 1 | //4034181 Jul 7, 2013 2:00:39 PM fuwutu 127A - Wasted Time GNU C++0x Accepted 15 ms 100 KB 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | int n, k; 11 | cin >> n >> k; 12 | 13 | double x, y, x0, y0, total(0.0); 14 | cin >> x0 >> y0; 15 | while (--n) 16 | { 17 | cin >> x >> y; 18 | total += sqrt((x - x0) * (x - x0) + (y - y0) * (y - y0)); 19 | x0 = x; 20 | y0 = y; 21 | } 22 | cout << fixed << setprecision(6) << total * k / 50 << endl; 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /194B - Square.cpp: -------------------------------------------------------------------------------- 1 | //4339876 Aug 26, 2013 6:25:52 PM fuwutu 194B - Square GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | 4 | int main() 5 | { 6 | int t; 7 | scanf("%d", &t); 8 | while (t--) 9 | { 10 | long long n; 11 | scanf("%I64d", &n); 12 | if ((n + 1) % 4 == 0) 13 | { 14 | printf("%I64d\n", n + 1); 15 | } 16 | else if ((n + 1) % 2 == 0) 17 | { 18 | printf("%I64d\n", n * 2 + 1); 19 | } 20 | else 21 | { 22 | printf("%I64d\n", n * 4 + 1); 23 | } 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /259A - Little Elephant and Chess.cpp: -------------------------------------------------------------------------------- 1 | //4034927 Jul 7, 2013 5:30:43 PM fuwutu 259A - Little Elephant and Chess GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | bool fail(false); 10 | string s; 11 | for (int i = 0; i < 8; ++i) 12 | { 13 | cin >> s; 14 | for (size_t j = 1; j < s.length(); ++j) 15 | { 16 | if (s[j] == s[j-1]) 17 | { 18 | fail = true; 19 | } 20 | } 21 | } 22 | cout << (fail ? "NO" : "YES") << endl; 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /110A - Nearly Lucky Number.cpp: -------------------------------------------------------------------------------- 1 | //4021277 Jul 4, 2013 7:21:06 PM fuwutu 110A - Nearly Lucky Number GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | long long n; 9 | cin >> n; 10 | int count = 0; 11 | while (n != 0) 12 | { 13 | if (n % 10 == 4 || n % 10 == 7) 14 | { 15 | count += 1; 16 | } 17 | n /= 10; 18 | } 19 | if (count == 4 || count == 7) 20 | { 21 | cout << "YES" << endl; 22 | } 23 | else 24 | { 25 | cout << "NO" << endl; 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /69A - Young Physicist.cpp: -------------------------------------------------------------------------------- 1 | //4027443 Jul 5, 2013 6:45:49 PM fuwutu 69A - Young Physicist GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, x, y, z, xsum(0), ysum(0), zsum(0); 9 | cin >> n; 10 | 11 | while (n--) 12 | { 13 | cin >> x >> y >> z; 14 | xsum += x; 15 | ysum += y; 16 | zsum += z; 17 | } 18 | 19 | if (xsum == 0 && ysum == 0 && zsum == 0) 20 | { 21 | cout << "YES" << endl; 22 | } 23 | else 24 | { 25 | cout << "NO" << endl; 26 | } 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /118A - String Task.cpp: -------------------------------------------------------------------------------- 1 | //4005085 Jul 3, 2013 3:50:19 AM fuwutu 118A - String Task GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | string s, r; 10 | cin >> s; 11 | for (char c : s) 12 | { 13 | if (c >= 'A' && c <= 'Z') 14 | { 15 | c += 'a' - 'A'; 16 | } 17 | if (c != 'a' && c != 'e' && c != 'i' && c != 'o' && c != 'u' && c != 'y') 18 | { 19 | r.append(1, '.'); 20 | r.append(1, c); 21 | } 22 | } 23 | cout << r << endl; 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /262B - Roma and Changing Signs.py: -------------------------------------------------------------------------------- 1 | #4286327 Aug 16, 2013 3:35:51 PM fuwutu 262B - Roma and Changing Signs Python 3 Accepted 280 ms 5500 KB 2 | l = input().split(' ') 3 | n, k = int(l[0]), int(l[1]) 4 | l = input().split(' ') 5 | answer = 0 6 | m = 10000 7 | for i in range(0, n): 8 | a = int(l[i]) 9 | if (a >= 0): 10 | answer += a 11 | if a < m: 12 | m = a 13 | else: 14 | if k > 0: 15 | answer -= a 16 | k -= 1 17 | else: 18 | answer += a 19 | if -a < m: 20 | m = -a 21 | if k % 2 == 1: 22 | answer -= m * 2 23 | print(answer) 24 | -------------------------------------------------------------------------------- /294A - Shaass and Oskols.cpp: -------------------------------------------------------------------------------- 1 | //4033248 Jul 7, 2013 9:12:31 AM fuwutu 294A - Shaass and Oskols GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, m, a[100+2], x, y; 9 | cin >> n; 10 | for (int i = 1; i <= n; ++i) 11 | { 12 | cin >> a[i]; 13 | } 14 | cin >> m; 15 | while (m--) 16 | { 17 | cin >> x >> y; 18 | a[x-1] += (y - 1); 19 | a[x+1] += (a[x] - y); 20 | a[x] = 0; 21 | } 22 | for (int i = 1; i <= n; ++i) 23 | { 24 | cout << a[i] << endl; 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /337A - Puzzles.cpp: -------------------------------------------------------------------------------- 1 | //4300351 Aug 17, 2013 4:18:19 AM fuwutu 337A - Puzzles GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int n, m, f[1000]; 10 | cin >> n >> m; 11 | for (int i = 0; i < m; ++i) 12 | { 13 | cin >> f[i]; 14 | } 15 | sort(f, f + m); 16 | int least = f[n-1] - f[0]; 17 | for (int i = 1; i <= m - n; ++i) 18 | { 19 | if (f[i+n-1] - f[i] < least) 20 | { 21 | least = f[i+n-1] - f[i]; 22 | } 23 | } 24 | cout << least << endl; 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /99A - Help Far Away Kingdom.cpp: -------------------------------------------------------------------------------- 1 | //4259472 Aug 10, 2013 7:43:30 AM fuwutu 99A - Help Far Away Kingdom GNU C++0x Accepted 62 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | string s; 10 | cin >> s; 11 | 12 | size_t n = s.find('.'); 13 | if (s[n-1] == '9') 14 | { 15 | cout << "GOTO Vasilisa." << endl; 16 | } 17 | else 18 | { 19 | if (s[n+1] >= '5') 20 | { 21 | s[n-1] += 1; 22 | } 23 | s.erase(s.begin() + n, s.end()); 24 | cout << s << endl; 25 | } 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /266B - Queue at the School.cpp: -------------------------------------------------------------------------------- 1 | //4021768 Jul 4, 2013 7:57:17 PM fuwutu 266B - Queue at the School GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int n, t; 10 | string s; 11 | cin >> n >> t >> s; 12 | while (t--) 13 | { 14 | for (int i = 1; i < n; ++i) 15 | { 16 | if (s[i] == 'G' && s[i-1] == 'B') 17 | { 18 | s[i] = 'B'; 19 | s[i-1] = 'G'; 20 | ++i; 21 | } 22 | } 23 | } 24 | cout << s << endl; 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /25A - IQ test.cpp: -------------------------------------------------------------------------------- 1 | //4034892 Jul 7, 2013 5:15:08 PM fuwutu 25A - IQ test GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, x, even(0), lastodd(0), lasteven(0); 9 | cin >> n; 10 | 11 | for (int i = 1; i <= n; ++i) 12 | { 13 | cin >> x; 14 | if (x % 2 == 0) 15 | { 16 | even += 1; 17 | lasteven = i; 18 | } 19 | else 20 | { 21 | even -= 1; 22 | lastodd = i; 23 | } 24 | } 25 | 26 | cout << (even > 0 ? lastodd : lasteven) << endl; 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /302B - Eugeny and Play List.cpp: -------------------------------------------------------------------------------- 1 | //4436009 Sep 9, 2013 6:53:39 PM fuwutu 302B - Eugeny and Play List GNU C++0x Accepted 156 ms 400 KB 2 | #include 3 | 4 | int main() 5 | { 6 | int n, m, s[100001]; 7 | s[0] = 0; 8 | scanf("%d%d", &n, &m); 9 | for (int i = 1; i <= n; ++i) 10 | { 11 | int c, t; 12 | scanf("%d%d", &c, &t); 13 | s[i] = s[i-1] + c * t; 14 | } 15 | int song = 1; 16 | while (m--) 17 | { 18 | int v; 19 | scanf("%d", &v); 20 | while (v > s[song]) 21 | { 22 | song += 1; 23 | } 24 | printf("%d\n", song); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /222A - Shooshuns and Sequence.cpp: -------------------------------------------------------------------------------- 1 | //4035123 Jul 7, 2013 6:28:36 PM fuwutu 222A - Shooshuns and Sequence GNU C++0x Accepted 31 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, k, a, last(0), continuous(1); 9 | scanf("%d%d", &n, &k); 10 | for (int i = 0; i < n; ++i) 11 | { 12 | scanf("%d", &a); 13 | if (a == last) 14 | { 15 | continuous += 1; 16 | } 17 | else 18 | { 19 | continuous = 1; 20 | } 21 | last = a; 22 | } 23 | printf("%d\n", continuous + k > n ? n - continuous: -1); 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /227B - Effective Approach.cpp: -------------------------------------------------------------------------------- 1 | //4263447 Aug 11, 2013 5:48:07 AM fuwutu 227B - Effective Approach GNU C++0x Accepted 92 ms 400 KB 2 | #include 3 | 4 | int main() 5 | { 6 | int n, a, index[100001]; 7 | scanf("%d", &n); 8 | for (int i = 1; i <= n; ++i) 9 | { 10 | scanf("%d", &a); 11 | index[a] = i; 12 | } 13 | 14 | int m, b; 15 | scanf("%d", &m); 16 | long long Vasya(0), Petya(0); 17 | while (m--) 18 | { 19 | scanf("%d", &b); 20 | Vasya += index[b]; 21 | Petya += (n + 1 - index[b]); 22 | } 23 | printf("%I64d %I64d\n", Vasya, Petya); 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /315A - Sereja and Bottles.cpp: -------------------------------------------------------------------------------- 1 | //4278687 Aug 14, 2013 8:29:33 PM fuwutu 315A - Sereja and Bottles GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | 4 | int main() 5 | { 6 | int n, a[1000], b[1000], c[1001] = {0}; 7 | scanf("%d", &n); 8 | for (int i = 0; i < n; ++i) 9 | { 10 | scanf("%d%d", &a[i], &b[i]); 11 | c[b[i]] += 1; 12 | } 13 | int count = 0; 14 | for (int i = 0; i < n; ++i) 15 | { 16 | c[b[i]] -= 1; 17 | if (c[a[i]] == 0) 18 | { 19 | count += 1; 20 | } 21 | c[b[i]] += 1; 22 | } 23 | printf("%d\n", count); 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /131C - The World is a Theatre.cpp: -------------------------------------------------------------------------------- 1 | //4212008 Aug 1, 2013 9:09:20 AM fuwutu 131C - The World is a Theatre GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | long long C(int n, int m) 7 | { 8 | long long result(1); 9 | for (int i = 0; i < m; ++i) 10 | { 11 | result *= (n - i); 12 | result /= (i + 1); 13 | } 14 | return result; 15 | } 16 | 17 | int main() 18 | { 19 | int n, m, t; 20 | cin >> n >> m >> t; 21 | 22 | long long ways(0); 23 | for (int i = 4; i <= t - 1; ++i) 24 | { 25 | ways += C(n, i) * C(m, t - i); 26 | } 27 | cout << ways << endl; 28 | } 29 | -------------------------------------------------------------------------------- /157B - Trace.cpp: -------------------------------------------------------------------------------- 1 | //4058096 Jul 13, 2013 9:59:34 AM fuwutu 157B - Trace GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | int main() 10 | { 11 | int n, a[100]; 12 | cin >> n; 13 | for (int i = 0; i < n; ++i) 14 | { 15 | cin >> a[i]; 16 | } 17 | sort(a, a + n, greater()); 18 | int rr(0); 19 | for (int i = 0; i < n; ++i) 20 | { 21 | rr += a[i] * a[i] * (1 - i % 2 * 2); 22 | } 23 | double pi = asin(1) * 2; 24 | cout << fixed << setprecision(10) << (pi * rr) << endl; 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /218A - Mountain Scenery.cpp: -------------------------------------------------------------------------------- 1 | //4306429 Aug 18, 2013 7:09:01 AM fuwutu 218A - Mountain Scenery GNU C++0x Accepted 62 ms 0 KB 2 | #include 3 | 4 | int main() 5 | { 6 | int n, k, r[201]; 7 | scanf("%d%d%d", &n, &k, &r[0]); 8 | for (int i = 1; i <= n * 2; i += 2) 9 | { 10 | scanf("%d%d", &r[i], &r[i+1]); 11 | if (k > 0 && r[i] > r[i-1] + 1 && r[i] > r[i+1] + 1) 12 | { 13 | k -= 1; 14 | r[i] -= 1; 15 | } 16 | } 17 | 18 | printf("%d", r[0]); 19 | for (int i = 1; i <= n * 2; ++i) 20 | { 21 | printf(" %d", r[i]); 22 | } 23 | printf("\n"); 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /23A - Youre Given a String.py: -------------------------------------------------------------------------------- 1 | #4271120 Aug 13, 2013 5:01:37 AM fuwutu 23A - Youre Given a String... Python 3 Accepted 342 ms 0 KB 2 | s = input() 3 | n = len(s) 4 | m = n - 1; 5 | while m > 0: 6 | find = False 7 | for i in range(0, n - m): 8 | for j in range(i + 1, n - m + 1): 9 | match = True 10 | for k in range(0, m): 11 | if s[i+k] != s[j+k]: 12 | match = False 13 | break 14 | if match: 15 | find = True 16 | break 17 | if find: 18 | break 19 | if find: 20 | break 21 | m -= 1 22 | print(m) 23 | -------------------------------------------------------------------------------- /322B - Ciel and Flowers.cpp: -------------------------------------------------------------------------------- 1 | //4264440 Aug 11, 2013 11:04:58 AM fuwutu 322B - Ciel and Flowers GNU C++0x Accepted 62 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | unsigned r, g, b; 10 | cin >> r >> g >> b; 11 | 12 | unsigned R(r % 3), G(g % 3), B(b % 3); 13 | unsigned amount(r / 3 + g / 3 + b / 3 + min(R, min(G, B))); 14 | if ( R == 2 && G == 2 && B == 0 && b != 0 15 | || G == 2 && B == 2 && R == 0 && r != 0 16 | || B == 2 && R == 2 && G == 0 && g != 0) 17 | { 18 | amount += 1; 19 | } 20 | cout << amount << endl; 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /80A - Panoramixs Prediction.cpp: -------------------------------------------------------------------------------- 1 | //4034860 Jul 7, 2013 5:08:41 PM fuwutu 80A - Panoramixs Prediction GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | bool isprime(int n) 7 | { 8 | for (int i = 2; i * i <= n; ++i) 9 | { 10 | if (n % i == 0) 11 | { 12 | return false; 13 | } 14 | } 15 | return true; 16 | } 17 | 18 | int main() 19 | { 20 | int n, m; 21 | cin >> n >> m; 22 | 23 | int next = n + 1; 24 | while (!isprime(next)) 25 | { 26 | next += 1; 27 | } 28 | 29 | cout << (next == m ? "YES" : "NO") << endl; 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /155A - I_love_%username%.cpp: -------------------------------------------------------------------------------- 1 | //4027892 Jul 5, 2013 8:45:43 PM fuwutu 155A - I_love_%username% GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, points; 9 | cin >> n >> points; 10 | int min(points), max(points), amazing(0); 11 | while (--n) 12 | { 13 | cin >> points; 14 | if (points < min) 15 | { 16 | min = points; 17 | ++amazing; 18 | } 19 | if (points > max) 20 | { 21 | max = points; 22 | ++amazing; 23 | } 24 | } 25 | cout << amazing << endl; 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /257A - Sockets.cpp: -------------------------------------------------------------------------------- 1 | //4238335 Aug 7, 2013 5:09:13 AM fuwutu 257A - Sockets GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | int n, m, k, a[50]; 11 | scanf("%d%d%d", &n, &m, &k); 12 | for (int i = 0; i < n; ++i) 13 | { 14 | scanf("%d", &a[i]); 15 | } 16 | 17 | sort(a, a + n, greater()); 18 | int filters(0), plug(k); 19 | while (filters < n && plug < m) 20 | { 21 | plug += a[filters] - 1; 22 | filters += 1; 23 | } 24 | printf("%d\n", plug >= m ? filters : -1); 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /137A - Postcards and photos.cpp: -------------------------------------------------------------------------------- 1 | //4035232 Jul 7, 2013 7:00:58 PM fuwutu 137A - Postcards and photos GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | string s; 10 | cin >> s; 11 | int result(0), count(1); 12 | for (size_t i = 1; i < s.length(); ++i) 13 | { 14 | if (s[i] == s[i-1]) 15 | { 16 | count += 1; 17 | } 18 | else 19 | { 20 | result += (count + 4) / 5; 21 | count = 1; 22 | } 23 | } 24 | result += (count + 4) / 5; 25 | cout << result << endl; 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /158B - Taxi.cpp: -------------------------------------------------------------------------------- 1 | //4005097 Jul 3, 2013 3:58:36 AM fuwutu 158B - Taxi GNU C++0x Accepted 46 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, s, count[5]= {0}; 9 | scanf("%d", &n); 10 | while (n--) 11 | { 12 | scanf("%d", &s); 13 | count[s] += 1; 14 | } 15 | int total = count[4] + count[3] + count[2] / 2; 16 | count[1] -= count[3]; 17 | if (count[2] % 2 == 1) 18 | { 19 | total += 1; 20 | count[1] -= 2; 21 | } 22 | if (count[1] > 0) 23 | { 24 | total += (count[1] + 3) / 4; 25 | } 26 | printf("%d\n", total); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /160A - Twins.cpp: -------------------------------------------------------------------------------- 1 | //4007272 Jul 3, 2013 7:54:19 PM fuwutu 160A - Twins GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | int n; 11 | cin >> n; 12 | 13 | vector a(n); 14 | for (int i = 0; i < n; ++i) 15 | { 16 | cin >> a[i]; 17 | } 18 | int value = accumulate(a.begin(), a.end(), 0) / 2; 19 | 20 | sort(a.begin(), a.end(), greater()); 21 | int mine = 0; 22 | size_t i = 0; 23 | while (mine <= value) 24 | { 25 | mine += a[i++]; 26 | } 27 | 28 | cout << i << endl; 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /284B - Cows and Poker Game.cpp: -------------------------------------------------------------------------------- 1 | //4035087 Jul 7, 2013 6:20:05 PM fuwutu 284B - Cows and Poker Game GNU C++0x Accepted 15 ms 200 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int n; 10 | char ch[200001]; 11 | scanf("%d%s", &n, ch); 12 | int allin = count(ch, ch + n, 'A'); 13 | int in = count(ch, ch + n, 'I'); 14 | int folded = count(ch, ch + n, 'F'); 15 | if (in == 1) 16 | { 17 | printf("1\n"); 18 | } 19 | else if (in == 0) 20 | { 21 | printf("%d\n", allin); 22 | } 23 | else 24 | { 25 | printf("0\n"); 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /74A - Room Leader.cpp: -------------------------------------------------------------------------------- 1 | //4189293 Jul 27, 2013 5:07:36 PM fuwutu 74A - Room Leader GNU C++0x Accepted 30 ms 100 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int n, plus, minus, a, b, c, d, e, top(-2501); 10 | string handle, leader; 11 | cin >> n; 12 | while (n--) 13 | { 14 | cin >> handle >> plus >> minus >> a >> b >> c >> d >> e; 15 | int points = plus * 100 - minus * 50 + a + b + c + d + e; 16 | if (points > top) 17 | { 18 | leader = handle; 19 | top = points; 20 | } 21 | } 22 | cout << leader; 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /131B - Opposites Attract.cpp: -------------------------------------------------------------------------------- 1 | //4034968 Jul 7, 2013 5:38:17 PM fuwutu 131B - Opposites Attract GNU C++0x Accepted 31 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, t, count[21] = {0}; 9 | scanf("%d", &n); 10 | while (n--) 11 | { 12 | scanf("%d", &t); 13 | count[t + 10] += 1; 14 | } 15 | long long result = static_cast(count[10]) * static_cast(count[10] - 1) /2; 16 | for (int i = 0; i < 10; ++i) 17 | { 18 | result += static_cast(count[i]) * static_cast(count[20 - i]); 19 | } 20 | printf("%I64d\n", result); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /136B - Ternary Logic.cpp: -------------------------------------------------------------------------------- 1 | //4172198 Jul 27, 2013 5:09:00 AM fuwutu 136B - Ternary Logic GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int a, c, ad[20] = {0}, an(0), cd[20] = {0}, cn(0); 9 | cin >> a >> c; 10 | 11 | while (a != 0) 12 | { 13 | ad[an++] = a % 3; 14 | a /= 3; 15 | } 16 | 17 | while (c != 0) 18 | { 19 | cd[cn++] = c % 3; 20 | c /= 3; 21 | } 22 | 23 | int tor(0); 24 | for (int i = max(an, cn) - 1; i >= 0; --i) 25 | { 26 | tor = tor * 3 + (cd[i] + 3 - ad[i]) % 3; 27 | } 28 | cout << tor << endl; 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /245A - System Administrator.cpp: -------------------------------------------------------------------------------- 1 | //4057519 Jul 13, 2013 6:52:47 AM fuwutu 245A - System Administrator GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, t, x, y, xa(0), ya(0), xb(0), yb(0); 9 | cin >> n; 10 | while (n--) 11 | { 12 | cin >> t >> x >> y; 13 | if (t == 1) 14 | { 15 | xa += x; 16 | ya += y; 17 | } 18 | else 19 | { 20 | xb += x; 21 | yb += y; 22 | } 23 | } 24 | cout << (xa >= ya ? "LIVE" : "DEAD") << endl; 25 | cout << (xb >= yb ? "LIVE" : "DEAD") << endl; 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /260A - Adding Digits.cpp: -------------------------------------------------------------------------------- 1 | //4076484 Jul 15, 2013 7:47:42 PM fuwutu 260A - Adding Digits GNU C++0x Accepted 15 ms 100 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int a, b, n; 10 | cin >> a >> b >> n; 11 | bool exist(false); 12 | for (int i = 0; i < 10; ++i) 13 | { 14 | if ((a * 10 + i) % b == 0) 15 | { 16 | cout << a * 10 + i; 17 | string s(n - 1, '0'); 18 | cout << s << endl; 19 | exist = true; 20 | break; 21 | } 22 | } 23 | if (!exist) 24 | { 25 | cout << -1 << endl; 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /35A - Shell Game.cpp: -------------------------------------------------------------------------------- 1 | //4265480 Aug 11, 2013 3:16:42 PM fuwutu 35A - Shell Game GNU C++0x Accepted 30 ms 100 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int x, a, b, cup[4] = {0}; 10 | 11 | freopen("input.txt", "r", stdin); 12 | freopen("output.txt", "w", stdout); 13 | 14 | scanf("%d", &x); 15 | cup[x] = 1; 16 | 17 | scanf("%d%d", &a, &b); 18 | swap(cup[a], cup[b]); 19 | 20 | scanf("%d%d", &a, &b); 21 | swap(cup[a], cup[b]); 22 | 23 | scanf("%d%d", &a, &b); 24 | swap(cup[a], cup[b]); 25 | 26 | printf("%d\n", find(cup + 1, cup + 3 + 1, 1) - cup); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /237A - Free Cash.cpp: -------------------------------------------------------------------------------- 1 | //4027473 Jul 5, 2013 6:52:44 PM fuwutu 237A - Free Cash GNU C++0x Accepted 46 ms 0 KB 2 | #include 3 | 4 | int main() 5 | { 6 | int n, h, m, h0, m0, c(1), cash(1); 7 | scanf("%d", &n); 8 | scanf("%d%d", &h0, &m0); 9 | 10 | while (--n) 11 | { 12 | scanf("%d%d", &h, &m); 13 | if (h == h0 && m == m0) 14 | { 15 | c += 1; 16 | if (c > cash) 17 | { 18 | cash = c; 19 | } 20 | } 21 | else 22 | { 23 | c = 1; 24 | } 25 | h0 = h; 26 | m0 = m; 27 | } 28 | printf("%d\n", cash); 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /252A - Little Xor.cpp: -------------------------------------------------------------------------------- 1 | //4304419 Aug 17, 2013 7:55:55 PM fuwutu 252A - Little Xor GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | 4 | int main() 5 | { 6 | int n, a, x[101] = {0}; 7 | scanf("%d", &n); 8 | for (int i = 1; i <= n; ++i) 9 | { 10 | scanf("%d", &a); 11 | x[i] = x[i-1] ^ a; 12 | } 13 | int maximal = 0; 14 | for (int i = 0; i < n; ++i) 15 | { 16 | for (int j = i + 1; j <= n; ++j) 17 | { 18 | int xx = x[i] ^ x[j]; 19 | if (xx > maximal) 20 | { 21 | maximal = xx; 22 | } 23 | } 24 | } 25 | printf("%d\n", maximal); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /255B - Code Parsing.cpp: -------------------------------------------------------------------------------- 1 | //4195173 Jul 28, 2013 6:14:10 PM fuwutu 255B - Code Parsing GNU C++0x Accepted 156 ms 2100 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | string s; 10 | cin >> s; 11 | 12 | int nx(0), ny(0); 13 | for (char c : s) 14 | { 15 | if (c == 'x') 16 | { 17 | nx += 1; 18 | } 19 | else 20 | { 21 | ny += 1; 22 | } 23 | } 24 | if (nx > ny) 25 | { 26 | s.assign(nx - ny, 'x'); 27 | } 28 | else 29 | { 30 | s.assign(ny - nx, 'y'); 31 | } 32 | cout << s << endl; 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /144A - Arrival of the General.cpp: -------------------------------------------------------------------------------- 1 | //4008690 Jul 4, 2013 3:55:22 AM fuwutu 144A - Arrival of the General GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, a; 9 | cin >> n >> a; 10 | int mina(a), maxa(a), mini(0), maxi(0); 11 | for (int i = 1; i < n; ++i) 12 | { 13 | cin >> a; 14 | if (a > maxa) 15 | { 16 | maxa = a; 17 | maxi = i; 18 | } 19 | if (a <= mina) 20 | { 21 | mina = a; 22 | mini = i; 23 | } 24 | } 25 | cout << maxi + (n - 1 - mini) - (mini < maxi ? 1 : 0) << endl; 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /4C - Registration System.cpp: -------------------------------------------------------------------------------- 1 | //4076800 Jul 15, 2013 9:04:58 PM fuwutu 4C - Registration System GNU C++0x Accepted 578 ms 900 KB 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | int n; 11 | cin >> n; 12 | 13 | map database; 14 | string s; 15 | while (n--) 16 | { 17 | cin >> s; 18 | if (database.count(s) == 0) 19 | { 20 | cout << "OK" << endl; 21 | database[s] = 1; 22 | } 23 | else 24 | { 25 | cout << s << database[s] << endl; 26 | database[s] += 1; 27 | } 28 | } 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /106A - Card Game.cpp: -------------------------------------------------------------------------------- 1 | //4235509 Aug 6, 2013 9:00:31 AM fuwutu 106A - Card Game GNU C++0x Accepted 62 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int rank(char c) 7 | { 8 | const char* order = "6789TJQKA"; 9 | char* find = const_cast(order); 10 | while (*find != c) 11 | { 12 | ++find; 13 | } 14 | return find - order; 15 | } 16 | 17 | int main() 18 | { 19 | char suit[2], card1[3], card2[3]; 20 | scanf("%s%s%s", suit, card1, card2); 21 | 22 | bool beat = (card1[1] == suit[0] && card2[1] != suit[0]) 23 | || (card1[1] == card2[1] && rank(card1[0]) > rank(card2[0])); 24 | printf(beat ? "YES\n" : "NO\n"); 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /259B - Little Elephant and Magic Square.cpp: -------------------------------------------------------------------------------- 1 | //4035330 Jul 7, 2013 7:30:59 PM fuwutu 259B - Little Elephant and Magic Square GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int x11, x12, x13, x21, x22, x23, x31, x32, x33; 9 | cin >> x11 >> x12 >> x13 >> x21 >> x22 >> x23 >> x31 >> x32 >> x33; 10 | int sum = (x12 + x13 + x21 + x23 + x31 + x32) / 2; 11 | x11 = sum - x12 - x13; 12 | x22 = sum - x21 - x23; 13 | x33 = sum - x31 - x32; 14 | cout << x11 << " " << x12 << " " << x13 << endl; 15 | cout << x21 << " " << x22 << " " << x23 << endl; 16 | cout << x31 << " " << x32 << " " << x33 << endl; 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /26A - Almost Prime.cpp: -------------------------------------------------------------------------------- 1 | //4240326 Aug 7, 2013 5:13:59 PM fuwutu 26A - Almost Prime GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | 4 | int main() 5 | { 6 | int n, amount(0); 7 | scanf("%d", &n); 8 | 9 | bool b[3001] = {false}; 10 | int pfactors[3001] = {0}; 11 | for (int i = 2; i <= n; ++i) 12 | { 13 | if (!b[i]) 14 | { 15 | for (int j = i + i; j <= n; j += i) 16 | { 17 | b[j] = true; 18 | pfactors[j] += 1; 19 | } 20 | } 21 | 22 | if (pfactors[i] == 2) 23 | { 24 | amount += 1; 25 | } 26 | } 27 | printf("%d\n", amount); 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /242B - Big Segment.cpp: -------------------------------------------------------------------------------- 1 | //4048451 Jul 11, 2013 3:40:15 AM fuwutu 242B - Big Segment GNU C++0x Accepted 62 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int n, l, r, minl, maxr, number(1); 10 | scanf("%d%d%d", &n, &minl, &maxr); 11 | for (int i = 2; i <= n; ++i) 12 | { 13 | scanf("%d%d", &l, &r); 14 | if (l <= minl && r >= maxr) 15 | { 16 | number = i; 17 | } 18 | else if (l < minl || r > maxr) 19 | { 20 | number = -1; 21 | } 22 | minl = min(minl, l); 23 | maxr = max(maxr, r); 24 | } 25 | printf("%d\n", number); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /282C - XOR and OR.cpp: -------------------------------------------------------------------------------- 1 | //4237725 Aug 6, 2013 9:18:15 PM fuwutu 282C - XOR and OR GNU C++0x Accepted 280 ms 3100 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | string a, b; 9 | cin >> a >> b; 10 | bool can(false); 11 | if (a.length() == b.length()) 12 | { 13 | size_t ia(0), ib(0); 14 | while (ia < a.length() && a[ia] == '0') 15 | ++ia; 16 | while (ib < b.length() && b[ib] == '0') 17 | ++ib; 18 | if ((ia < a.length() && ib < b.length()) 19 | || (ia == a.length() && ib == b.length())) 20 | can = true; 21 | } 22 | cout << (can ? "YES" : "NO") << endl; 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /302A - Eugeny and Array.cpp: -------------------------------------------------------------------------------- 1 | //4076621 Jul 15, 2013 8:14:28 PM fuwutu 302A - Eugeny and Array GNU C++0x Accepted 187 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int n, m, a, l, r, c(0), d(0); 10 | scanf("%d%d", &n, &m); 11 | while (n--) 12 | { 13 | scanf("%d", &a); 14 | if (a == 1) 15 | { 16 | c += 1; 17 | } 18 | else 19 | { 20 | d += 1; 21 | } 22 | } 23 | int up = min(c, d) * 2; 24 | while (m--) 25 | { 26 | scanf("%d%d", &l, &r); 27 | printf((r - l) % 2 == 1 && r - l < up ? "1\n" : "0\n"); 28 | } 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /6A - Triangle.cpp: -------------------------------------------------------------------------------- 1 | //4240257 Aug 7, 2013 4:45:32 PM fuwutu 6A - Triangle GNU C++0x Accepted 62 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int length[4]; 10 | scanf("%d%d%d%d", &length[0], &length[1], &length[2], &length[3]); 11 | sort(length, length + 4); 12 | if (length[0] + length[1] > length[2] || length[1] + length[2] > length[3]) 13 | { 14 | printf("TRIANGLE\n"); 15 | } 16 | else if (length[0] + length[1] == length[2] || length[1] + length[2] == length[3]) 17 | { 18 | printf("SEGMENT\n"); 19 | } 20 | else 21 | { 22 | printf("IMPOSSIBLE\n"); 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /146A - Lucky Ticket.cpp: -------------------------------------------------------------------------------- 1 | //4033946 Jul 7, 2013 12:54:50 PM fuwutu 146A - Lucky Ticket GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | size_t n; 10 | string s; 11 | cin >> n >> s; 12 | 13 | bool lucky = true; 14 | int diff(0); 15 | n /= 2; 16 | for (size_t i = 0; i < n; ++i) 17 | { 18 | if ((s[i] != '4' && s[i] != '7') || (s[n+i] != '4' && s[n+i] !='7')) 19 | { 20 | lucky = false; 21 | break; 22 | } 23 | diff += (s[i] - s[n+i]); 24 | } 25 | lucky = lucky && (diff == 0); 26 | cout << (lucky ? "YES" : "NO") << endl; 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /158A - Next Round.cpp: -------------------------------------------------------------------------------- 1 | //4004018 Jul 2, 2013 8:42:28 PM fuwutu 158A - Next Round GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, k; 9 | cin >> n >> k; 10 | 11 | int a; 12 | for (int i = 0; i < k; ++i) 13 | { 14 | cin >> a; 15 | if (a == 0) 16 | { 17 | cout << i << endl; 18 | return 0; 19 | } 20 | } 21 | 22 | int b; 23 | for (int i = k; i < n; ++i) 24 | { 25 | cin >> b; 26 | if (b != a) 27 | { 28 | cout << i << endl; 29 | return 0; 30 | } 31 | } 32 | 33 | cout << n << endl; 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /268A - Games.cpp: -------------------------------------------------------------------------------- 1 | //4021898 Jul 4, 2013 8:08:38 PM fuwutu 268A - Games GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int n; 10 | cin >> n; 11 | 12 | int number(0); 13 | vector h(n), a(n); 14 | for (int i = 0; i < n; ++i) 15 | { 16 | cin >> h[i] >> a[i]; 17 | for (int j = 0; j < i; ++j) 18 | { 19 | if (h[i] == a[j]) 20 | { 21 | number += 1; 22 | } 23 | if (a[i] == h[j]) 24 | { 25 | number += 1; 26 | } 27 | } 28 | } 29 | cout << number << endl; 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /29A - Spit Problem.cpp: -------------------------------------------------------------------------------- 1 | //4285064 Aug 16, 2013 9:06:46 AM fuwutu 29A - Spit Problem GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | 4 | int main() 5 | { 6 | int n, x[100], d[100]; 7 | bool spitted = false; 8 | scanf("%d", &n); 9 | for (int i = 0; i < n; ++i) 10 | { 11 | scanf("%d%d", &x[i], &d[i]); 12 | for (int j = 0; j < i; ++j) 13 | { 14 | if (x[i] + d[i] == x[j] && x[j] + d[j] == x[i]) 15 | { 16 | spitted = true; 17 | break; 18 | } 19 | } 20 | if (spitted) 21 | { 22 | break; 23 | } 24 | } 25 | printf(spitted ? "YES\n" : "NO\n"); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /313B - Ilya and Queries.cpp: -------------------------------------------------------------------------------- 1 | //4055457 Jul 12, 2013 6:54:18 PM fuwutu 313B - Ilya and Queries GNU C++0x Accepted 109 ms 500 KB 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | char s[100001]; 8 | int a[100001], m, l, r; 9 | 10 | scanf("%s%d", s, &m); 11 | int len = strlen(s); 12 | 13 | a[1] = 0; 14 | for (int i = 1; i < len; ++i) 15 | { 16 | if (s[i] == s[i-1]) 17 | { 18 | a[i+1] = a[i] + 1; 19 | } 20 | else 21 | { 22 | a[i+1] = a[i]; 23 | } 24 | } 25 | 26 | while (m--) 27 | { 28 | scanf("%d%d", &l, &r); 29 | printf("%d\n", a[r] - a[l]); 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /330B - Road Construction.cpp: -------------------------------------------------------------------------------- 1 | //4225560 Aug 4, 2013 5:26:26 AM fuwutu B - Road Construction GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | 4 | int main() 5 | { 6 | int n, m, a, b; 7 | bool fire[1001] = {false}; 8 | scanf("%d%d", &n, &m); 9 | while (m--) 10 | { 11 | scanf("%d%d", &a, &b); 12 | fire[a] = true; 13 | fire[b] = true; 14 | } 15 | int x = 1; 16 | while (fire[x]) 17 | { 18 | x++; 19 | } 20 | printf("%d\n", n - 1); 21 | for (int i = 1; i < x; ++i) 22 | { 23 | printf("%d %d\n", i, x); 24 | } 25 | for (int i = x + 1; i <= n; ++i) 26 | { 27 | printf("%d %d\n", x, i); 28 | } 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /75A - Life Without Zeros.cpp: -------------------------------------------------------------------------------- 1 | //4059137 Jul 13, 2013 2:18:42 PM fuwutu 75A - Life Without Zeros GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int remove0(int n) 7 | { 8 | int m(0), pow(1); 9 | while (n != 0) 10 | { 11 | int d = n % 10; 12 | n /= 10; 13 | if (d != 0) 14 | { 15 | m += d * pow; 16 | pow *= 10; 17 | } 18 | } 19 | return m; 20 | } 21 | 22 | int main() 23 | { 24 | int a, b; 25 | cin >> a >> b; 26 | int c = a + b; 27 | int A = remove0(a); 28 | int B = remove0(b); 29 | int C = remove0(c); 30 | cout << (A + B == C ? "YES" : "NO") << endl; 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /96A - Football.cpp: -------------------------------------------------------------------------------- 1 | //4007191 Jul 3, 2013 7:32:32 PM fuwutu 96A - Football GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | string s; 10 | cin >> s; 11 | 12 | int contiguous = 1; 13 | for (size_t i = 1; i < s.length(); ++i) 14 | { 15 | if (s[i] == s[i - 1]) 16 | { 17 | contiguous += 1; 18 | if (contiguous == 7) 19 | { 20 | cout << "YES" << endl; 21 | return 0; 22 | } 23 | } 24 | else 25 | { 26 | contiguous = 1; 27 | } 28 | } 29 | 30 | cout << "NO" << endl; 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /118B - Present from Lena.cpp: -------------------------------------------------------------------------------- 1 | //4027858 Jul 5, 2013 8:37:21 PM fuwutu 118B - Present from Lena GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int n; 10 | cin >> n; 11 | 12 | for (int row = -n; row <= n; ++row) 13 | { 14 | int top = n - abs(row); 15 | for (int i = 0; i < abs(row); ++i) 16 | { 17 | cout << " "; 18 | } 19 | for (int i = 0; i < top; ++i) 20 | { 21 | cout << i << " "; 22 | } 23 | for (int i = top; i > 0; --i) 24 | { 25 | cout << i << " "; 26 | } 27 | cout << 0 << endl; 28 | } 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /262A - Roma and Lucky Numbers.cpp: -------------------------------------------------------------------------------- 1 | //4033968 Jul 7, 2013 12:59:41 PM fuwutu 262A - Roma and Lucky Numbers GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int n, k, count(0); 10 | cin >> n >> k; 11 | 12 | string s; 13 | while (n--) 14 | { 15 | int lucky(0); 16 | cin >> s; 17 | for (size_t i = 0; i < s.length(); ++i) 18 | { 19 | if (s[i] == '4' || s[i] == '7') 20 | { 21 | lucky += 1; 22 | } 23 | } 24 | if (lucky <= k) 25 | { 26 | count += 1; 27 | } 28 | } 29 | cout << count << endl; 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /43A - Football.cpp: -------------------------------------------------------------------------------- 1 | //4057616 Jul 13, 2013 7:20:24 AM fuwutu 43A - Football GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int n, goal(0); 10 | cin >> n; 11 | 12 | string team, win; 13 | while (n--) 14 | { 15 | if (goal != 0) 16 | { 17 | cin >> team; 18 | if (team == win) 19 | { 20 | goal += 1; 21 | } 22 | else 23 | { 24 | goal -= 1; 25 | } 26 | } 27 | else 28 | { 29 | cin >> win; 30 | goal = 1; 31 | } 32 | } 33 | cout << win << endl; 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /94A - Restoring Password.cpp: -------------------------------------------------------------------------------- 1 | //4263203 Aug 11, 2013 4:19:31 AM fuwutu 94A - Restoring Password GNU C++0x Accepted 62 ms 100 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | string s, digit[10]; 10 | cin >> s; 11 | for (size_t i = 0; i < sizeof(digit) / sizeof(digit[0]); ++i) 12 | { 13 | cin >> digit[i]; 14 | } 15 | for (size_t i = 0; i < 8; ++i) 16 | { 17 | string x = s.substr(i * 10, 10); 18 | for (size_t j = 0; j < 10; ++j) 19 | { 20 | if (x == digit[j]) 21 | { 22 | cout << j; 23 | break; 24 | } 25 | } 26 | } 27 | cout << endl; 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /119A - Epic Game.cpp: -------------------------------------------------------------------------------- 1 | //4006915 Jul 3, 2013 6:07:36 PM fuwutu 119A - Epic Game GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int GCD(int m, int n) 7 | { 8 | int r; 9 | while ((r = m % n) != 0) 10 | { 11 | m = n; 12 | n = r; 13 | } 14 | return n; 15 | } 16 | 17 | int main() 18 | { 19 | int a, b, n; 20 | cin >> a >> b >> n; 21 | while (true) 22 | { 23 | n -= GCD(a, n); 24 | if (n == 0) 25 | { 26 | cout << 0 << endl; 27 | break; 28 | } 29 | n -= GCD(b, n); 30 | if (n == 0) 31 | { 32 | cout << 1 << endl; 33 | break; 34 | } 35 | } 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /244A - Dividing Orange.cpp: -------------------------------------------------------------------------------- 1 | //4035355 Jul 7, 2013 7:39:20 PM fuwutu 244A - Dividing Orange GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, k, a[30]; 9 | bool b[901] = {false}; 10 | cin >> n >> k; 11 | for (int i = 0; i < k; ++i) 12 | { 13 | cin >> a[i]; 14 | b[a[i]] = true; 15 | } 16 | int d = 0; 17 | for (int i = 0; i < k; ++i) 18 | { 19 | cout << a[i]; 20 | for (int j = 1; j < n; ++j) 21 | { 22 | ++d; 23 | while (b[d]) 24 | { 25 | ++d; 26 | } 27 | cout << " " << d; 28 | } 29 | cout << endl; 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /291A - Spyke Talks.cpp: -------------------------------------------------------------------------------- 1 | //4033186 Jul 7, 2013 8:44:41 AM fuwutu 291A - Spyke Talks GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int n, id[1000]; 10 | cin >> n; 11 | for (int i = 0; i < n; ++i) 12 | { 13 | cin >> id[i]; 14 | } 15 | sort(id, id + n); 16 | int pairs = 0; 17 | for (int i = 1; i < n; ++i) 18 | { 19 | if (id[i] != 0 && id[i] == id[i-1]) 20 | { 21 | pairs += 1; 22 | if (i + 1 < n && id[i] == id[i+1]) 23 | { 24 | pairs = -1; 25 | break; 26 | } 27 | } 28 | } 29 | cout << pairs << endl; 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /276A - Lunch Rush.cpp: -------------------------------------------------------------------------------- 1 | //4032976 Jul 7, 2013 6:40:04 AM fuwutu 276A - Lunch Rush GNU C++0x Accepted 31 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, k, f, t, max_joy, joy; 9 | cin >> n >> k >> f >> t; 10 | if (t > k) 11 | { 12 | max_joy = f - (t - k); 13 | } 14 | else 15 | { 16 | max_joy = f; 17 | } 18 | while (--n) 19 | { 20 | cin >> f >> t; 21 | if (t > k) 22 | { 23 | joy = f - (t - k); 24 | } 25 | else 26 | { 27 | joy = f; 28 | } 29 | if (joy > max_joy) 30 | { 31 | max_joy = joy; 32 | } 33 | } 34 | cout << max_joy << endl; 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /13A - Numbers.cpp: -------------------------------------------------------------------------------- 1 | //4264970 Aug 11, 2013 1:04:16 PM fuwutu 13A - Numbers GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | 4 | int GCD(int m, int n) 5 | { 6 | int r = m % n; 7 | while (r != 0) 8 | { 9 | m = n; 10 | n = r; 11 | r = m % n; 12 | } 13 | return n; 14 | } 15 | 16 | int main() 17 | { 18 | int A; 19 | scanf("%d", &A); 20 | 21 | int X(0), Y(A-2); 22 | for (int base = 2; base < A; ++base) 23 | { 24 | int n(A), ds(0); 25 | while (n != 0) 26 | { 27 | ds += n % base; 28 | n /= base; 29 | } 30 | X += ds; 31 | } 32 | 33 | int gcd = GCD(X, Y); 34 | X /= gcd; 35 | Y /= gcd; 36 | printf("%d/%d\n", X, Y); 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /327A - Flipping Game.cpp: -------------------------------------------------------------------------------- 1 | //4057739 Jul 13, 2013 7:54:54 AM fuwutu 327A - Flipping Game GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, a, count1(0), extra0(0), extra0max(-1); 9 | cin >> n; 10 | while (n--) 11 | { 12 | cin >> a; 13 | if (a == 1) 14 | { 15 | count1 += 1; 16 | if (extra0 > 0) 17 | { 18 | extra0 -= 1; 19 | } 20 | } 21 | else 22 | { 23 | extra0 += 1; 24 | if (extra0 > extra0max) 25 | { 26 | extra0max = extra0; 27 | } 28 | } 29 | } 30 | cout << count1 + extra0max << endl; 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /320A - Magic Numbers.cpp: -------------------------------------------------------------------------------- 1 | //4057462 Jul 13, 2013 6:34:24 AM fuwutu 320A - Magic Numbers GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, state(0); 9 | cin >> n; 10 | 11 | bool magic(true); 12 | while (n != 0) 13 | { 14 | int d = n % 10; 15 | n /= 10; 16 | 17 | if (d == 1) 18 | { 19 | state = 0; 20 | } 21 | else if (d == 4 && state < 2) 22 | { 23 | state = state + 1; 24 | } 25 | else 26 | { 27 | magic = false; 28 | } 29 | } 30 | if (state != 0) 31 | { 32 | magic = false; 33 | } 34 | cout << (magic ? "YES" : "NO") << endl; 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /242A - Heads or Tails.cpp: -------------------------------------------------------------------------------- 1 | //4052591 Jul 12, 2013 3:41:55 AM fuwutu 242A - Heads or Tails GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int x, y, a, b; 9 | cin >> x >> y >> a >> b; 10 | int count = 0; 11 | for (int Vasya = a; Vasya <= x; ++Vasya) 12 | { 13 | int end = min(Vasya - 1, y); 14 | if (b <= end) 15 | { 16 | count += (end - b + 1); 17 | } 18 | } 19 | cout << count << endl; 20 | for (int Vasya = a; Vasya <= x; ++Vasya) 21 | { 22 | int end = min(Vasya - 1, y); 23 | for (int Petya = b; Petya <= end; ++Petya) 24 | { 25 | cout << Vasya << " " << Petya << endl; 26 | } 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /32A - Reconnaissance.cpp: -------------------------------------------------------------------------------- 1 | //4265527 Aug 11, 2013 3:28:43 PM fuwutu 32A - Reconnaissance GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int n, d, height[1000]; 10 | scanf("%d%d", &n, &d); 11 | for (int i = 0; i < n; ++i) 12 | { 13 | scanf("%d", &height[i]); 14 | } 15 | 16 | sort(height, height + n); 17 | 18 | int i1 = 0, i2 = 1, ways = 0; 19 | while (i2 < n) 20 | { 21 | if (height[i2] - height[i1] <= d) 22 | { 23 | ways += (i2 - i1); 24 | ++i2; 25 | } 26 | else 27 | { 28 | ++i1; 29 | } 30 | } 31 | ways *= 2; 32 | 33 | printf("%d\n", ways); 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /333B - Chips.cpp: -------------------------------------------------------------------------------- 1 | //4188914 Jul 27, 2013 4:36:49 PM fuwutu 333B - Chips GNU C++0x Accepted 62 ms 0 KB 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | int n, m, x, y, row[1001], col[1001]; 11 | scanf("%d%d", &n, &m); 12 | fill(row + 1, row + n + 1, 1); 13 | fill(col + 1, col + n + 1, 1); 14 | 15 | while (m--) 16 | { 17 | scanf("%d%d", &x, &y); 18 | row[x] = 0; 19 | col[y] = 0; 20 | } 21 | 22 | int points = accumulate(row + 2, row + n, 0) + accumulate(col + 2, col + n, 0); 23 | if (n >= 3 && n % 2 == 1 && row[n / 2 + 1] == 1 && col[n / 2 + 1] == 1) 24 | { 25 | points -= 1; 26 | } 27 | 28 | printf("%d\n", points); 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /279B - Books.cpp: -------------------------------------------------------------------------------- 1 | //4057901 Jul 13, 2013 8:57:44 AM fuwutu 279B - Books GNU C++0x Accepted 31 ms 400 KB 2 | #include 3 | 4 | int main() 5 | { 6 | int n, t, a[100000]; 7 | scanf("%d%d", &n, &t); 8 | for (int i = 0; i < n; ++i) 9 | { 10 | scanf("%d", &a[i]); 11 | } 12 | 13 | int j(0), time(0); 14 | while (j < n && time + a[j] <= t) 15 | { 16 | time += a[j++]; 17 | } 18 | int maximum(j); 19 | for (int i = 0; i < n; ++i) 20 | { 21 | time -= a[i]; 22 | while (j < n && time + a[j] <= t) 23 | { 24 | time += a[j++]; 25 | } 26 | if (j - i - 1 > maximum) 27 | { 28 | maximum = j - i - 1; 29 | } 30 | } 31 | printf("%d\n", maximum); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /318B - Strings of Power.cpp: -------------------------------------------------------------------------------- 1 | //4240656 Aug 7, 2013 7:27:25 PM fuwutu 318B - Strings of Power GNU C++0x Accepted 156 ms 2100 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | string s; 9 | cin >> s; 10 | 11 | int heavy(0); 12 | long long amount(0); 13 | for (size_t i = 4; i < s.length(); ++i) 14 | { 15 | if (s[i] == 'l') 16 | { 17 | if (s[i-4] == 'm' && s[i-3] == 'e' && s[i-2] == 't' && s[i-1] == 'a') 18 | { 19 | amount += heavy; 20 | } 21 | } 22 | else if (s[i-4] == 'h' && s[i-3] == 'e' && s[i-2] == 'a' && s[i-1] == 'v' && s[i] == 'y') 23 | { 24 | ++heavy; 25 | } 26 | } 27 | cout << amount << endl; 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /7A - Kalevitch and Chess.cpp: -------------------------------------------------------------------------------- 1 | //4306015 Aug 18, 2013 4:11:33 AM fuwutu 7A - Kalevitch and Chess GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | char s[9]; 10 | bool row[8] = {false}, col[8] = {false}; 11 | for (int r = 0; r < 8; ++r) 12 | { 13 | scanf("%s", s); 14 | for (int c = 0; c < 9; ++c) 15 | { 16 | if (s[c] == 'W') 17 | { 18 | row[r] = true; 19 | col[c] = true; 20 | } 21 | } 22 | } 23 | int answer = 16 - count(row, row + 8, true) - count(col, col + 8, true); 24 | if (answer == 16) 25 | { 26 | answer = 8; 27 | } 28 | printf("%d\n", answer); 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /149A - Business trip.cpp: -------------------------------------------------------------------------------- 1 | //4032903 Jul 7, 2013 5:41:16 AM fuwutu 149A - Business trip GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int k, a[12], total(0); 10 | cin >> k; 11 | for (size_t i = 0; i < 12; ++i) 12 | { 13 | cin >> a[i]; 14 | total += a[i]; 15 | } 16 | 17 | if (total < k) 18 | { 19 | cout << -1 << endl; 20 | } 21 | else 22 | { 23 | sort(a, a + sizeof(a) / sizeof(a[0]), greater()); 24 | int sum = 0; 25 | int month = 0; 26 | while (sum < k) 27 | { 28 | sum += a[month]; 29 | month += 1; 30 | } 31 | cout << month << endl; 32 | } 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /78A - Haiku.cpp: -------------------------------------------------------------------------------- 1 | //4172472 Jul 27, 2013 5:55:14 AM fuwutu 78A - Haiku GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | char ch[101]; 9 | int syllables[3] = {5, 7, 5}; 10 | bool haiku(true); 11 | for (int i = 0; i < 3; ++i) 12 | { 13 | cin.getline(ch, sizeof(ch) / sizeof(ch[0])); 14 | int n = 0; 15 | for (int j = 0; ch[j] != 0; ++j) 16 | { 17 | if (ch[j] == 'a' || ch[j] == 'e' || ch[j] == 'i' || ch[j] == 'o' || ch[j] == 'u') 18 | { 19 | n += 1; 20 | } 21 | } 22 | if (n != syllables[i]) 23 | { 24 | haiku = false; 25 | } 26 | } 27 | cout << (haiku ? "YES" : "NO") << endl; 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /116B - Little Pigs and Wolves.cpp: -------------------------------------------------------------------------------- 1 | //4057937 Jul 13, 2013 9:13:14 AM fuwutu 116B - Little Pigs and Wolves GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | int main() 5 | { 6 | int n, m; 7 | char c[12][13]; 8 | scanf("%d%d", &n, &m); 9 | for (int i = 1; i <= n; ++i) 10 | { 11 | scanf("%s", &c[i][1]); 12 | } 13 | int eaten(0); 14 | for (int i = 1; i <= n; ++i) 15 | { 16 | for (int j = 1; j <= m; ++j) 17 | { 18 | if (c[i][j] == 'W') 19 | { 20 | if (c[i-1][j] == 'P' || c[i+1][j] == 'P' || c[i][j-1] == 'P' || c[i][j+1] == 'P') 21 | { 22 | eaten += 1; 23 | } 24 | } 25 | } 26 | } 27 | printf("%d\n", eaten); 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /298A - Snow Footprints.cpp: -------------------------------------------------------------------------------- 1 | //4205157 Jul 30, 2013 8:24:41 PM fuwutu 298A - Snow Footprints GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | size_t n; 10 | string s; 11 | cin >> n >> s; 12 | 13 | for (size_t i = 0; i < n; ++i) 14 | { 15 | if (s[i] != '.') 16 | { 17 | if (s[i] == 'R') 18 | { 19 | while (s[i] == 'R') 20 | { 21 | ++i; 22 | } 23 | cout << i << " " << i + 1 << endl; 24 | } 25 | else 26 | { 27 | cout << i + 1 << " " << i << endl; 28 | } 29 | break; 30 | } 31 | } 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /205A - Little Elephant and Rozdil.cpp: -------------------------------------------------------------------------------- 1 | //4035181 Jul 7, 2013 6:43:30 PM fuwutu 205A - Little Elephant and Rozdil GNU C++0x Accepted 46 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, time, min_time(1000000001), min_index(0), count(1); 9 | scanf("%d", &n); 10 | for (int i = 1; i <= n; ++i) 11 | { 12 | scanf("%d", &time); 13 | if (time < min_time) 14 | { 15 | min_time = time; 16 | min_index = i; 17 | count = 1; 18 | } 19 | else if (time == min_time) 20 | { 21 | count += 1; 22 | } 23 | } 24 | if (count == 1) 25 | { 26 | printf("%d\n", min_index); 27 | } 28 | else 29 | { 30 | printf("Still Rozdil\n"); 31 | } 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /253A - Boys and Girls.cpp: -------------------------------------------------------------------------------- 1 | //4059072 Jul 13, 2013 1:57:50 PM fuwutu 253A - Boys and Girls GNU C++0x Accepted 15 ms 200 KB 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | size_t n, m; 11 | 12 | freopen("input.txt", "r", stdin); 13 | freopen("output.txt", "w", stdout); 14 | cin >> n >> m; 15 | 16 | if (n >= m) 17 | { 18 | string s(n+m, 'B'); 19 | for (size_t i = 1; i < m * 2; i += 2) 20 | { 21 | s[i] = 'G'; 22 | } 23 | cout << s << endl; 24 | } 25 | else 26 | { 27 | string s(m+n, 'G'); 28 | for (size_t i = 1; i < n * 2; i += 2) 29 | { 30 | s[i] = 'B'; 31 | } 32 | cout << s << endl; 33 | } 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /275A - Lights Out.cpp: -------------------------------------------------------------------------------- 1 | //4033486 Jul 7, 2013 10:57:25 AM fuwutu 275A - Lights Out GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int x11, x12, x13, x21, x22, x23, x31, x32, x33; 9 | cin >> x11 >> x12 >> x13 >> x21 >> x22 >> x23 >> x31 >> x32 >> x33; 10 | cout << ((x11 + x12 + x21) % 2 == 0 ? "1" : "0") << ((x11 + x12 + x13 + x22) % 2 == 0 ? "1" : "0") << ((x12 + x13 + x23) % 2 == 0 ? "1" : "0") << endl; 11 | cout << ((x11 + x21 + x22 + x31) % 2 == 0 ? "1" : "0") << ((x12 + x21 + x22 + x23 + x32) % 2 == 0 ? "1" : "0") << ((x13 + x22 + x23 + x33) % 2 == 0 ? "1" : "0") << endl; 12 | cout << ((x21 + x31 + x32) % 2 == 0 ? "1" : "0") << ((x22 + x31 + x32 + x33) % 2 == 0 ? "1" : "0") << ((x23 + x32 + x33) % 2 == 0 ? "1" : "0") << endl; 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /131A - cAPS lOCK.cpp: -------------------------------------------------------------------------------- 1 | //4006936 Jul 3, 2013 6:14:19 PM fuwutu 131A - cAPS lOCK GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | string s; 9 | cin >> s; 10 | 11 | bool change = true; 12 | for (size_t i = 1; i < s.length(); ++i) 13 | { 14 | if (s[i] >= 'a') 15 | { 16 | change = false; 17 | break; 18 | } 19 | } 20 | 21 | if (change) 22 | { 23 | for (size_t i = 0; i < s.length(); ++i) 24 | { 25 | if (s[i] >= 'a') 26 | { 27 | s[i] -= ('a' - 'A'); 28 | } 29 | else 30 | { 31 | s[i] += ('a' - 'A'); 32 | } 33 | } 34 | } 35 | 36 | cout << s << endl; 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /16A - Flag.cpp: -------------------------------------------------------------------------------- 1 | //4264767 Aug 11, 2013 12:13:45 PM fuwutu 16A - Flag GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | 4 | int main() 5 | { 6 | int n, m; 7 | scanf("%d%d", &n, &m); 8 | 9 | bool meet(true); 10 | char color[101], prev('*'); 11 | while (n--) 12 | { 13 | scanf("%s", color); 14 | if (color[0] == prev) 15 | { 16 | meet = false; 17 | break; 18 | } 19 | prev = color[0]; 20 | 21 | for (int i = 1; i < m; ++i) 22 | { 23 | if (color[i] != color[0]) 24 | { 25 | meet = false; 26 | break; 27 | } 28 | } 29 | 30 | if (!meet) 31 | { 32 | break; 33 | } 34 | } 35 | printf(meet ? "YES\n" : "NO\n"); 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /106B - Choosing Laptop.cpp: -------------------------------------------------------------------------------- 1 | //4265752 Aug 11, 2013 4:22:47 PM fuwutu 106B - Choosing Laptop GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int n, speed[101], ram[101], hdd[101], cost[101]; 10 | scanf("%d", &n); 11 | for (int i = 1; i <= n; ++i) 12 | { 13 | scanf("%d%d%d%d", &speed[i], &ram[i], &hdd[i], &cost[i]); 14 | } 15 | 16 | for (int i = 1; i <= n; ++i) 17 | { 18 | for (int j = 1; j <= n; ++j) 19 | { 20 | if (speed[i] < speed[j] && ram[i] < ram[j] && hdd[i] < hdd[j]) 21 | { 22 | cost[i] = 1001; // 100 <= cost <= 1000 23 | } 24 | } 25 | } 26 | 27 | printf("%u\n", min_element(cost + 1, cost + 1 + n) - cost); 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /102B - Sum of Digits.cpp: -------------------------------------------------------------------------------- 1 | //4192333 Jul 28, 2013 6:06:57 AM fuwutu 102B - Sum of Digits GNU C++0x Accepted 30 ms 100 KB 2 | #include 3 | 4 | int main() 5 | { 6 | char digits[100001]; 7 | scanf("%s", digits); 8 | 9 | int times(0); 10 | if (digits[1] != 0) 11 | { 12 | int digitsum(0); 13 | char* p = digits; 14 | while (*p != 0) 15 | { 16 | digitsum += (*p - '0'); 17 | ++p; 18 | } 19 | ++times; 20 | 21 | while (digitsum > 9) 22 | { 23 | int m(digitsum); 24 | digitsum = 0; 25 | while (m != 0) 26 | { 27 | digitsum += m % 10; 28 | m /= 10; 29 | } 30 | ++times; 31 | } 32 | } 33 | printf("%d\n", times); 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /22A - Second Order Statistics.cpp: -------------------------------------------------------------------------------- 1 | //4265058 Aug 11, 2013 1:29:54 PM fuwutu 22A - Second Order Statistics GNU C++0x Accepted 62 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int n, a[101]; 10 | scanf("%d", &n); 11 | for (int i = 1; i <= n; ++i) 12 | { 13 | scanf("%d", &a[i]); 14 | } 15 | 16 | int x = *min_element(a + 1, a + n + 1); 17 | int value2(x); 18 | for (int i = 1; i <= n; ++i) 19 | { 20 | if (a[i] > x) 21 | { 22 | if (value2 == x || a[i] < value2) 23 | { 24 | value2 = a[i]; 25 | } 26 | } 27 | } 28 | 29 | if (value2 != x) 30 | { 31 | printf("%d\n", value2); 32 | } 33 | else 34 | { 35 | printf("NO\n"); 36 | } 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /34A - Reconnaissance 2.cpp: -------------------------------------------------------------------------------- 1 | //4172496 Jul 27, 2013 6:04:28 AM fuwutu 34A - Reconnaissance 2 GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int n, a1; 10 | cin >> n >> a1; 11 | 12 | int prev(a1), cur, reconnaissance(1000), index1, index2; 13 | for (int i = 2; i <= n; ++i) 14 | { 15 | cin >> cur; 16 | int diff = abs(cur - prev); 17 | if (diff < reconnaissance) 18 | { 19 | reconnaissance = diff; 20 | index1 = i - 1; 21 | index2 = i; 22 | } 23 | prev = cur; 24 | } 25 | int diff = abs(a1 - prev); 26 | if (diff < reconnaissance) 27 | { 28 | index1 = n; 29 | index2 = 1; 30 | } 31 | cout << index1 << " " << index2 << endl; 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /58A - Chat room.cpp: -------------------------------------------------------------------------------- 1 | //4027656 Jul 5, 2013 7:34:35 PM fuwutu 58A - Chat room GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | string s; 10 | cin >> s; 11 | 12 | size_t pos = 0; 13 | while (pos < s.length() && s[pos] != 'h') 14 | ++pos; 15 | ++pos; 16 | while (pos < s.length() && s[pos] != 'e') 17 | ++pos; 18 | ++pos; 19 | while (pos < s.length() && s[pos] != 'l') 20 | ++pos; 21 | ++pos; 22 | while (pos < s.length() && s[pos] != 'l') 23 | ++pos; 24 | ++pos; 25 | while (pos < s.length() && s[pos] != 'o') 26 | ++pos; 27 | 28 | if (pos < s.length()) 29 | { 30 | cout << "YES" << endl; 31 | } 32 | else 33 | { 34 | cout << "NO" << endl; 35 | } 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /49A - Sleuth.cpp: -------------------------------------------------------------------------------- 1 | //4231238 Aug 5, 2013 8:54:36 AM fuwutu 49A - Sleuth GNU C++0x Accepted 62 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | char s[110]; 9 | cin.getline(s, sizeof(s) / sizeof(s[0]), '\n'); 10 | bool vowel(true); 11 | char* p = s; 12 | while (*p != '\0') 13 | { 14 | if (*p >= 'a' && *p <= 'z' || *p >= 'A' && *p <= 'Z') 15 | { 16 | if (*p == 'a' ||*p == 'e' ||*p == 'i' ||*p == 'o' ||*p == 'u' ||*p == 'y' || 17 | *p == 'A' ||*p == 'E' ||*p == 'I' ||*p == 'O' ||*p == 'U' ||*p == 'Y') 18 | { 19 | vowel = true; 20 | } 21 | else 22 | { 23 | vowel = false; 24 | } 25 | } 26 | ++p; 27 | } 28 | cout << (vowel ? "YES" : "NO") << endl; 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /155B - Combination.cpp: -------------------------------------------------------------------------------- 1 | //4136855 Jul 22, 2013 9:19:15 PM fuwutu 155B - Combination GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | struct card 8 | { 9 | int a; 10 | int b; 11 | }; 12 | 13 | bool cmp(const card& left, const card& right) 14 | { 15 | return (left.b > right.b) 16 | || (left.b == right.b && left.a > right.a); 17 | } 18 | 19 | int main() 20 | { 21 | int n; 22 | scanf("%d", &n); 23 | 24 | card c[1000]; 25 | for (int i = 0; i < n; ++i) 26 | { 27 | scanf("%d%d", &c[i].a, &c[i].b); 28 | } 29 | 30 | sort(c, c + n, cmp); 31 | int points(c[0].a), cards(c[0].b); 32 | for (int i = 1; i < n && i <= cards; ++i) 33 | { 34 | points += c[i].a; 35 | cards += c[i].b; 36 | } 37 | 38 | printf("%d\n", points); 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /59A - Word.cpp: -------------------------------------------------------------------------------- 1 | //4033867 Jul 7, 2013 12:41:33 PM fuwutu 59A - Word GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | string s; 11 | cin >> s; 12 | int upper(0), lower(0); 13 | for (size_t i = 0; i < s.length(); ++i) 14 | { 15 | if (isupper(s[i])) 16 | { 17 | upper += 1; 18 | } 19 | else 20 | { 21 | lower += 1; 22 | } 23 | } 24 | if (upper > lower) 25 | { 26 | for (size_t i = 0; i < s.length(); ++i) 27 | { 28 | s[i] = toupper(s[i]); 29 | } 30 | } 31 | else 32 | { 33 | for (size_t i = 0; i < s.length(); ++i) 34 | { 35 | s[i] = tolower(s[i]); 36 | } 37 | } 38 | cout << s << endl; 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /141A - Amusing Joke.cpp: -------------------------------------------------------------------------------- 1 | //4027532 Jul 5, 2013 7:07:08 PM fuwutu 141A - Amusing Joke GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | int dict[128] = {0}; 11 | string s; 12 | cin >> s; 13 | for (size_t i = 0; i < s.length(); ++i) 14 | { 15 | dict[s[i]] += 1; 16 | } 17 | cin >> s; 18 | for (size_t i = 0; i < s.length(); ++i) 19 | { 20 | dict[s[i]] += 1; 21 | } 22 | cin >> s; 23 | for (size_t i = 0; i < s.length(); ++i) 24 | { 25 | dict[s[i]] -= 1; 26 | } 27 | 28 | if (count(dict, dict + sizeof(dict) / sizeof(dict[0]), 0) == sizeof(dict) / sizeof(*dict)) 29 | { 30 | cout << "YES" << endl; 31 | } 32 | else 33 | { 34 | cout << "NO" << endl; 35 | } 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /296A - Yaroslav and Permutations.cpp: -------------------------------------------------------------------------------- 1 | //4052601 Jul 12, 2013 3:50:47 AM fuwutu 296A - Yaroslav and Permutations GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int n, a[100]; 10 | cin >> n; 11 | for (int i = 0; i < n; ++i) 12 | { 13 | cin >> a[i]; 14 | } 15 | sort(a, a + n); 16 | int continuous(1), max_continuous(1); 17 | for (int i = 1; i < n; ++i) 18 | { 19 | if (a[i] == a[i-1]) 20 | { 21 | continuous += 1; 22 | if (continuous > max_continuous) 23 | { 24 | max_continuous = continuous; 25 | } 26 | } 27 | else 28 | { 29 | continuous = 1; 30 | } 31 | } 32 | cout << (max_continuous <= (n + 1) / 2 ? "YES" : "NO") << endl; 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /315B - Sereja and Array.cpp: -------------------------------------------------------------------------------- 1 | //4215408 Aug 2, 2013 9:09:42 AM fuwutu 315B - Sereja and Array GNU C++0x Accepted 156 ms 400 KB 2 | #include 3 | 4 | int main() 5 | { 6 | int n, m, a[100001], t, v, x, y, q, increase(0); 7 | scanf("%d%d", &n, &m); 8 | for (int i = 1; i <= n; ++i) 9 | { 10 | scanf("%d", &a[i]); 11 | } 12 | 13 | while (m--) 14 | { 15 | scanf("%d", &t); 16 | switch (t) 17 | { 18 | case 1: 19 | scanf("%d%d", &v, &x); 20 | a[v] = x - increase; 21 | break; 22 | 23 | case 2: 24 | scanf("%d", &y); 25 | increase += y; 26 | break; 27 | 28 | case 3: 29 | scanf("%d", &q); 30 | printf("%d\n", a[q] + increase); 31 | break; 32 | 33 | default: 34 | break; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /66B - Petya and Countryside.cpp: -------------------------------------------------------------------------------- 1 | //4306556 Aug 18, 2013 7:48:28 AM fuwutu 66B - Petya and Countryside GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | 4 | int main() 5 | { 6 | int n, height[1000], left[1000] = {0}, right[1000] = {0}; 7 | scanf("%d", &n); 8 | for (int i = 0; i < n; ++i) 9 | { 10 | scanf("%d", &height[i]); 11 | } 12 | 13 | for (int i = 1; i < n; ++i) 14 | { 15 | left[i] = (height[i] >= height[i-1] ? left[i-1] + 1 : 0); 16 | } 17 | for (int i = n - 2; i >= 0; --i) 18 | { 19 | right[i] = (height[i] >= height[i+1] ? right[i+1] + 1 : 0); 20 | } 21 | 22 | int maximal(0); 23 | for (int i = 0; i < n; ++i) 24 | { 25 | if (left[i] + right[i] + 1 > maximal) 26 | { 27 | maximal = left[i] + right[i] + 1; 28 | } 29 | } 30 | printf("%d\n", maximal); 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /157A - Game Outcome.cpp: -------------------------------------------------------------------------------- 1 | //4042683 Jul 9, 2013 5:48:49 PM fuwutu 157A - Game Outcome GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, m[30][30], r[30] = {0}, c[30] = {0}, win(0); 9 | cin >> n; 10 | for (int i = 0; i < n; ++i) 11 | { 12 | for (int j = 0; j < n; ++j) 13 | { 14 | cin >> m[i][j]; 15 | r[i] += m[i][j]; 16 | } 17 | } 18 | for (int j = 0; j < n; ++j) 19 | { 20 | for (int i = 0; i < n; ++i) 21 | { 22 | c[j] += m[i][j]; 23 | } 24 | } 25 | for (int i = 0; i < n; ++i) 26 | { 27 | for (int j = 0; j < n; ++j) 28 | { 29 | if (r[i] < c[j]) 30 | { 31 | win += 1; 32 | } 33 | } 34 | } 35 | cout << win << endl; 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /17A - Noldbach problem.cpp: -------------------------------------------------------------------------------- 1 | //4264838 Aug 11, 2013 12:28:28 PM fuwutu 17A - Noldbach problem GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | 4 | int main() 5 | { 6 | int n, k; 7 | scanf("%d%d", &n, &k); 8 | 9 | int prime[1000] = {3, 5}, count(2); 10 | for (int number = 7; number <= n && k != 0; number += 2) 11 | { 12 | int i = 0; 13 | while (i < count && number % prime[i] != 0) 14 | { 15 | ++i; 16 | } 17 | if (i == count) 18 | { 19 | for (int j = 1; j < count; ++j) 20 | { 21 | if (prime[j] + prime[j-1] + 1 == number) 22 | { 23 | k -= 1; 24 | break; 25 | } 26 | } 27 | prime[count++] = number; 28 | } 29 | } 30 | printf(k == 0 ? "YES\n" : "NO\n"); 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /336A - Vasily the Bear and Triangle.cpp: -------------------------------------------------------------------------------- 1 | //4259668 Aug 10, 2013 8:56:45 AM fuwutu00:06 336A - Vasily the Bear and Triangle GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int x, y; 10 | cin >> x >> y; 11 | if (x > 0) 12 | { 13 | if (y > 0) 14 | { 15 | cout << 0 << " " << x + y << " " << x + y << " " << 0 << endl; 16 | } 17 | else 18 | { 19 | cout << 0 << " " << y - x << " " << x - y << " " << 0 << endl;; 20 | } 21 | } 22 | else 23 | { 24 | if (y > 0) 25 | { 26 | cout << x - y << " " << 0 << " " << 0 << " " << y - x << endl;; 27 | } 28 | else 29 | { 30 | cout << x + y << " " << 0 << " " << 0 << " " << x + y << endl;; 31 | } 32 | } 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /330A - Cakeminator.cpp: -------------------------------------------------------------------------------- 1 | //4172001 Jul 27, 2013 4:19:28 AM fuwutu 330A - Cakeminator GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int r, c, row[11] = {0}, col[11] ={0}; 10 | string s; 11 | cin >> r >> c; 12 | for (int i = 0; i < r; ++i) 13 | { 14 | cin >> s; 15 | for (int j = 0; j < c; ++j) 16 | { 17 | if (s[j] == 'S') 18 | { 19 | row[i] = 1; 20 | col[j] = 1; 21 | } 22 | } 23 | } 24 | int cakes(0); 25 | for (int i = 0; i < r; ++i) 26 | { 27 | for (int j = 0; j < c; ++j) 28 | { 29 | if (row[i] == 0 || col[j] == 0) 30 | { 31 | cakes += 1; 32 | } 33 | } 34 | } 35 | cout << cakes << endl; 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /12B - Correct Solution.cpp: -------------------------------------------------------------------------------- 1 | //4264747 Aug 11, 2013 12:07:08 PM fuwutu 12B - Correct Solution? GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | int n; 11 | char m[11], digit[10] = {'0'}, digitcount(0); 12 | scanf("%d%s", &n, &m); 13 | 14 | while (n != 0) 15 | { 16 | digit[digitcount++] = '0' + n % 10; 17 | n /= 10; 18 | } 19 | 20 | sort(digit, digit + digitcount); 21 | 22 | if (digit[0] == '0') 23 | { 24 | for (int i = 1; i < digitcount; ++i) 25 | { 26 | if (digit[i] != '0') 27 | { 28 | digit[0] = digit[i]; 29 | digit[i] = '0'; 30 | break; 31 | } 32 | } 33 | } 34 | 35 | printf(strcmp(m, digit) == 0 ? "OK\n" : "WRONG_ANSWER\n"); 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /276C - Little Girl and Maximum Sum.cpp: -------------------------------------------------------------------------------- 1 | //4306317 Aug 18, 2013 6:33:43 AM fuwutu 276C - Little Girl and Maximum Sum GNU C++0x Accepted 218 ms 1500 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int a[200000], c[200001] = {0}; 8 | 9 | int main() 10 | { 11 | int n, q, l, r; 12 | scanf("%d%d", &n, &q); 13 | for (int i = 0; i < n; ++i) 14 | { 15 | scanf("%d", &a[i]); 16 | } 17 | while (q--) 18 | { 19 | scanf("%d%d", &l, &r); 20 | c[l-1] += 1; 21 | c[r] -= 1; 22 | } 23 | for (int i = 1; i < n; ++i) 24 | { 25 | c[i] += c[i-1]; 26 | } 27 | 28 | sort(a, a + n); 29 | sort(c, c + n); 30 | long long answer = 0; 31 | for (int i = 0; i < n; ++i) 32 | { 33 | answer += static_cast(a[i]) * static_cast(c[i]); 34 | } 35 | printf("%I64d\n", answer); 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /3A - Shortest path of the king.cpp: -------------------------------------------------------------------------------- 1 | //4124738 Jul 21, 2013 4:00:21 AM fuwutu 3A - Shortest path of the king GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | string s, t; 10 | cin >> s >> t; 11 | cout << max(abs(s[0] - t[0]), abs(s[1] - t[1])) << endl; 12 | while (s != t) 13 | { 14 | if (s[0] < t[0]) 15 | { 16 | cout << "R"; 17 | s[0] += 1; 18 | } 19 | else if (s[0] > t[0]) 20 | { 21 | cout << "L"; 22 | s[0] -= 1; 23 | } 24 | 25 | if (s[1] < t[1]) 26 | { 27 | cout << "U"; 28 | s[1] += 1; 29 | } 30 | else if (s[1] > t[1]) 31 | { 32 | cout << "D"; 33 | s[1] -= 1; 34 | } 35 | 36 | cout << endl; 37 | } 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /219A - k-String.cpp: -------------------------------------------------------------------------------- 1 | //4033694 Jul 7, 2013 11:59:29 AM fuwutu 219A - k-String GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int k; 10 | string s; 11 | cin >> k >> s; 12 | 13 | int count[26] = {0}; 14 | for (size_t i = 0; i < s.length(); ++i) 15 | { 16 | count[s[i]-'a'] += 1; 17 | } 18 | 19 | string s1; 20 | size_t c = 0; 21 | for (; c < 26; ++c) 22 | { 23 | if (count[c] % k != 0) 24 | { 25 | break; 26 | } 27 | else 28 | { 29 | s1.append(count[c] / k, 'a' + c); 30 | } 31 | } 32 | if (c == 26) 33 | { 34 | while (k--) 35 | { 36 | cout << s1; 37 | } 38 | cout << endl; 39 | } 40 | else 41 | { 42 | cout << -1 << endl; 43 | } 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /160B - Unlucky Ticket.cpp: -------------------------------------------------------------------------------- 1 | //4033517 Jul 7, 2013 11:10:00 AM fuwutu 160B - Unlucky Ticket GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | size_t n; 11 | string s, l, r; 12 | cin >> n >> s; 13 | l = s.substr(0, n); 14 | r = s.substr(n, n); 15 | sort(l.begin(), l.end()); 16 | sort(r.begin(), r.end()); 17 | bool strictly_less(true), strictly_more(true); 18 | for (size_t i = 0; i < n; ++i) 19 | { 20 | if (l[i] >= r[i]) 21 | { 22 | strictly_less = false; 23 | break; 24 | } 25 | } 26 | for (size_t i = 0; i < n; ++i) 27 | { 28 | if (l[i] <= r[i]) 29 | { 30 | strictly_more = false; 31 | break; 32 | } 33 | } 34 | cout << ((strictly_less || strictly_more) ? "YES" : "NO") << endl; 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /208D - Prizes, Prizes, more Prizes.cpp: -------------------------------------------------------------------------------- 1 | //4263589 Aug 11, 2013 6:26:48 AM fuwutu 208D - Prizes, Prizes, more Prizes GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | 4 | int main() 5 | { 6 | int n, p[50], a, b, c, d, e, points(0), mug(0), towel(0), bag(0), bicycle(0), car(0); 7 | scanf("%d", &n); 8 | for (int i = 0; i < n; ++i) 9 | { 10 | scanf("%d", &p[i]); 11 | } 12 | scanf("%d%d%d%d%d", &a, &b, &c, &d, &e); 13 | 14 | for (int i = 0; i < n; ++i) 15 | { 16 | points += p[i]; 17 | 18 | car += points / e; 19 | points %= e; 20 | bicycle += points / d; 21 | points %= d; 22 | bag += points / c; 23 | points %= c; 24 | towel += points / b; 25 | points %= b; 26 | mug += points / a; 27 | points %= a; 28 | } 29 | printf("%I64d %I64d %I64d %I64d %I64d\n%d\n", mug, towel, bag, bicycle, car, points); 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /143A - Help Vasilisa the Wise 2.cpp: -------------------------------------------------------------------------------- 1 | //4236777 Aug 6, 2013 3:58:53 PM fuwutu 143A - Help Vasilisa the Wise 2 GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int r1, r2, c1, c2, d1, d2; 9 | cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; 10 | int a11 = (r1 + c1 - d2) / 2; 11 | int a12 = r1 - a11; 12 | int a21 = c1 - a11; 13 | int a22 = d1 - a11; 14 | if (a11 != a12 && a11 != a21 && a11 != a22 && a12 != a21 && a12 != a22 && a21 != a22 15 | && a11 >= 1 && a11 <= 9 16 | && a12 >= 1 && a12 <= 9 17 | && a21 >= 1 && a21 <= 9 18 | && a22 >= 1 && a22 <= 9 19 | && a21 + a22 == r2 20 | && a12 + a22 == c2 21 | && a12 + a21 == d2) 22 | { 23 | cout << a11 << " " << a12 << endl; 24 | cout << a21 << " " << a22 << endl; 25 | } 26 | else 27 | { 28 | cout << -1 << endl; 29 | } 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /208A - Dubstep.cpp: -------------------------------------------------------------------------------- 1 | //4032897 Jul 7, 2013 5:34:34 AM fuwutu 208A - Dubstep GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | string s; 11 | cin >> s; 12 | 13 | vector words; 14 | size_t start = 0; 15 | while (true) 16 | { 17 | size_t end = s.find("WUB", start); 18 | if (end == string::npos) 19 | { 20 | words.push_back(s.substr(start, end)); 21 | break; 22 | } 23 | if (end != start) 24 | { 25 | words.push_back(s.substr(start, end - start)); 26 | } 27 | start = end + 3; 28 | } 29 | 30 | if (!words.empty()) 31 | { 32 | cout << words[0]; 33 | } 34 | for (size_t i = 1; i < words.size(); ++i) 35 | { 36 | cout << " " << words[i]; 37 | } 38 | cout << endl; 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /255A - Greg's Workout.cpp: -------------------------------------------------------------------------------- 1 | //4033282 Jul 7, 2013 9:25:08 AM fuwutu 255A - Greg's Workout GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, a, b, c, chest(0), biceps(0), back(0); 9 | cin >> n; 10 | for (int i = 0; i < n / 3; ++i) 11 | { 12 | cin >> a >> b >> c; 13 | chest += a; 14 | biceps += b; 15 | back += c; 16 | } 17 | if (n % 3 == 1) 18 | { 19 | cin >> a; 20 | chest += a; 21 | } 22 | else if (n % 3 == 2) 23 | { 24 | cin >> a >> b; 25 | chest += a; 26 | biceps += b; 27 | } 28 | if (chest > biceps && chest > back) 29 | { 30 | cout << "chest" << endl; 31 | } 32 | else if (biceps > back && biceps > chest) 33 | { 34 | cout << "biceps" << endl; 35 | } 36 | else 37 | { 38 | cout << "back" << endl; 39 | } 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /215A - Bicycle Chain.cpp: -------------------------------------------------------------------------------- 1 | //4034009 Jul 7, 2013 1:12:56 PM fuwutu 215A - Bicycle Chain GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, m, a[50], b, max(0), count(1); 9 | cin >> n; 10 | for (int i = 0; i < n; ++i) 11 | { 12 | cin >> a[i]; 13 | } 14 | cin >> m; 15 | for (int i = 0; i < m; ++i) 16 | { 17 | cin >> b; 18 | for (int j = 0; j < n; ++j) 19 | { 20 | if (b % a[j] == 0) 21 | { 22 | int x = b / a[j]; 23 | if (x > max) 24 | { 25 | max = x; 26 | count = 1; 27 | } 28 | else if (x == max) 29 | { 30 | count += 1; 31 | } 32 | break; 33 | } 34 | } 35 | } 36 | cout << count << endl; 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /186A - Строкосравнитель.cpp: -------------------------------------------------------------------------------- 1 | //4240233 Aug 7, 2013 4:37:55 PM fuwutu 186A - Строкосравнитель GNU C++0x Accepted 62 ms 200 KB 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | char s1[100001], s2[100001]; 8 | scanf("%s%s", s1, s2); 9 | 10 | int len1 = strlen(s1); 11 | int len2 = strlen(s2); 12 | 13 | bool same = false; 14 | if (len1 == len2) 15 | { 16 | int diff[3], diffcount(0); 17 | for (int i = 0; i < len1; ++i) 18 | { 19 | if (s1[i] != s2[i]) 20 | { 21 | diff[diffcount++] = i; 22 | if (diffcount == 3) 23 | { 24 | break; 25 | } 26 | } 27 | } 28 | if (diffcount == 2 && s1[diff[0]] == s2[diff[1]] && s1[diff[1]] == s2[diff[0]]) 29 | { 30 | same = true; 31 | } 32 | } 33 | printf(same ? "YES\n" : "NO\n"); 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /122A - Lucky Division.cpp: -------------------------------------------------------------------------------- 1 | //4027427 Jul 5, 2013 6:40:47 PM fuwutu 122A - Lucky Division GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | bool lucky(int n) 7 | { 8 | while (n != 0) 9 | { 10 | if (n % 10 != 4 && n % 10 != 7) 11 | { 12 | return false; 13 | } 14 | n /= 10; 15 | } 16 | return true; 17 | } 18 | 19 | bool almost_lucky(int n) 20 | { 21 | if (lucky(n)) 22 | { 23 | return true; 24 | } 25 | 26 | for (int i = 2; i * i <= n; ++i) 27 | { 28 | if (n % i == 0 && (lucky(i) || lucky(n / i))) 29 | { 30 | return true; 31 | } 32 | } 33 | 34 | return false; 35 | } 36 | 37 | int main() 38 | { 39 | int n; 40 | cin >> n; 41 | if (almost_lucky(n)) 42 | { 43 | cout << "YES" << endl; 44 | } 45 | else 46 | { 47 | cout << "NO" << endl; 48 | } 49 | 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /272B - Dima and Sequence.cpp: -------------------------------------------------------------------------------- 1 | //4265639 Aug 11, 2013 3:54:36 PM fuwutu 272B - Dima and Sequence GNU C++0x Accepted 62 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int bitcount(int n) 7 | { 8 | n = (n & 0x55555555) + ((n >> 1) & 0x55555555) ; 9 | n = (n & 0x33333333) + ((n >> 2) & 0x33333333) ; 10 | n = (n & 0x0f0f0f0f) + ((n >> 4) & 0x0f0f0f0f) ; 11 | n = (n & 0x00ff00ff) + ((n >> 8) & 0x00ff00ff) ; 12 | n = (n & 0x0000ffff) + ((n >> 16) & 0x0000ffff) ; 13 | return n ; 14 | } 15 | 16 | int main() 17 | { 18 | int n, a, c[32] = {0}; 19 | scanf("%d", &n); 20 | while (n--) 21 | { 22 | scanf("%d", &a); 23 | c[bitcount(a)] += 1; 24 | } 25 | 26 | long long answer = 0; 27 | for (size_t i = 0; i < sizeof(c) / sizeof(c[0]); ++i) 28 | { 29 | answer += static_cast(c[i]) * static_cast(c[i] - 1) / 2; 30 | } 31 | printf("%I64d\n", answer); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /264A - Escape from Stones.cpp: -------------------------------------------------------------------------------- 1 | //4275242 Aug 14, 2013 5:03:19 AM fuwutu 264A - Escape from Stones GNU C++0x Accepted 498 ms 8800 KB 2 | #include 3 | #include 4 | 5 | char s[1000001]; 6 | int left[1000002]; 7 | int right[1000002]; 8 | 9 | int main() 10 | { 11 | scanf("%s", s); 12 | int n = strlen(s); 13 | 14 | right[0] = n + 1; 15 | right[n + 1] = 0; 16 | 17 | int l = 0, r = n + 1; 18 | for (int i = 1; i <= n; ++i) 19 | { 20 | right[l] = i; 21 | left[i] = l; 22 | 23 | right[i] = r; 24 | left[r] = i; 25 | 26 | switch (s[i-1]) 27 | { 28 | case 'l': 29 | r = i; 30 | break; 31 | case 'r': 32 | l = i; 33 | break; 34 | default: 35 | break; 36 | } 37 | } 38 | 39 | int x = 0; 40 | while (n--) 41 | { 42 | x = right[x]; 43 | printf("%d\n", x); 44 | } 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /342A - Xenia and Divisors.cpp: -------------------------------------------------------------------------------- 1 | //4592917 Sep 28, 2013 4:40:12 AM fuwutu 342A - Xenia and Divisors GNU C++0x Accepted 62 ms 0 KB 2 | #include 3 | 4 | int main() 5 | { 6 | int n, x, count[8] = {0}; 7 | scanf("%d", &n); 8 | for (int i = 0; i < n; ++i) 9 | { 10 | scanf("%d", &x); 11 | count[x] += 1; 12 | } 13 | 14 | bool solution; 15 | if (count[5] == 0 && count[7] == 0 && count[2] >= count[4] && count[1] == count[4] + count[6] && count[2] + count[3] == count[4] + count[6]) 16 | { 17 | for (int i = 0; i < count[4]; ++i) 18 | { 19 | printf("1 2 4\n"); 20 | } 21 | count[2] -= count[4]; 22 | for (int i = 0; i < count[2]; ++i) 23 | { 24 | printf("1 2 6\n"); 25 | } 26 | for (int i = 0; i < count[3]; ++i) 27 | { 28 | printf("1 3 6\n"); 29 | } 30 | } 31 | else 32 | { 33 | printf("-1\n"); 34 | } 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /337C - Quiz.cpp: -------------------------------------------------------------------------------- 1 | //4302392 Aug 17, 2013 1:03:52 PM fuwutu 337C - Quiz GNU C++0x Accepted 62 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | long long n, m, k; 9 | cin >> n >> m >> k; 10 | long long wrong = n - m; 11 | if ((wrong + 1) * (k - 1) >= m) 12 | { 13 | cout << m << endl; 14 | } 15 | else 16 | { 17 | long long consecutive = m - wrong * (k - 1); 18 | long long t = consecutive / k; 19 | long long result = 1; 20 | long long pow = 2; 21 | long long tt = t; 22 | while (tt != 0) 23 | { 24 | if (tt % 2 == 1) 25 | { 26 | result *= pow; 27 | result %= 1000000009LL; 28 | } 29 | tt /= 2; 30 | pow = pow * pow % 1000000009LL; 31 | } 32 | result = ((result - 1) * 2 * k+ m - t * k) % 1000000009LL; 33 | cout << result << endl; 34 | } 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /4B - Before an Exam.cpp: -------------------------------------------------------------------------------- 1 | //4239012 Aug 7, 2013 10:06:36 AM fuwutu 4B - Before an Exam GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | int d, sumTime, minTime[30], maxTime[30]; 11 | scanf("%d%d", &d, &sumTime); 12 | for (int i = 0; i < d; ++i) 13 | { 14 | scanf("%d%d", &minTime[i], &maxTime[i]); 15 | } 16 | int minTimeSum = accumulate(minTime, minTime + d, 0); 17 | int maxTimeSum = accumulate(maxTime, maxTime + d, 0); 18 | if (minTimeSum <= sumTime && sumTime <= maxTimeSum) 19 | { 20 | printf("YES\n"); 21 | for (int i = 0; i < d; ++i) 22 | { 23 | int t = min(minTime[i] + sumTime - minTimeSum, maxTime[i]); 24 | printf((i + 1 < d ? "%d " : "%d\n"), t); 25 | sumTime -= (t - minTime[i]); 26 | } 27 | } 28 | else 29 | { 30 | printf("NO\n"); 31 | } 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /230A - Dragons.cpp: -------------------------------------------------------------------------------- 1 | //4032937 Jul 7, 2013 6:12:45 AM fuwutu 230A - Dragons GNU C++0x Accepted 15 ms 100 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | struct dragon 8 | { 9 | int x; 10 | int y; 11 | }; 12 | 13 | bool cmp(const dragon& left, const dragon& right) 14 | { 15 | return left.x < right.x; 16 | } 17 | 18 | int main() 19 | { 20 | int s, n; 21 | cin >> s >> n; 22 | 23 | dragon d[10000]; 24 | for (int i = 0; i < n; ++i) 25 | { 26 | cin >> d[i].x >> d[i].y; 27 | } 28 | sort(d, d + n, cmp); 29 | 30 | int boss = d[n-1].x; 31 | for (int i = 0; i < n && s <= boss; ++i) 32 | { 33 | if (s > d[i].x) 34 | { 35 | s += d[i].y; 36 | } 37 | else 38 | { 39 | break; 40 | } 41 | } 42 | 43 | if (s > boss) 44 | { 45 | cout << "YES" << endl; 46 | } 47 | else 48 | { 49 | cout << "NO" << endl; 50 | } 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /31A - Worms Evolution.cpp: -------------------------------------------------------------------------------- 1 | //4265591 Aug 11, 2013 3:43:45 PM fuwutu 31A - Worms Evolution GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, a[101]; 9 | scanf("%d", &n); 10 | for (int i = 1; i <= n; ++i) 11 | { 12 | scanf("%d", &a[i]); 13 | } 14 | 15 | bool found = false; 16 | for (int i = 1; !found && i <= n; ++i) 17 | { 18 | for (int j = 1; !found && j <= n; ++j) 19 | { 20 | if (j != i) 21 | { 22 | for (int k = j + 1; k <= n; ++k) 23 | { 24 | if (k != i && a[i] == a[j] + a[k]) 25 | { 26 | printf("%d %d %d\n", i, j, k); 27 | found = true; 28 | break; 29 | } 30 | } 31 | } 32 | } 33 | } 34 | 35 | if (!found) 36 | { 37 | printf("-1\n"); 38 | } 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /189A - Cut Ribbon.cpp: -------------------------------------------------------------------------------- 1 | //4240283 Aug 7, 2013 4:58:38 PM fuwutu 189A - Cut Ribbon GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int n, a, b, c, maximum(0); 10 | scanf("%d%d%d%d", &n, &a, &b, &c); 11 | 12 | bool x[4001] = {false}, y[8001] = {false}; 13 | x[0] = true; 14 | for (int step = 1; ; ++step) 15 | { 16 | int count(0); 17 | for (int i = 0; i <= n; ++i) 18 | { 19 | if (x[i]) 20 | { 21 | y[i+a] = true; 22 | y[i+b] = true; 23 | y[i+c] = true; 24 | count += 1; 25 | } 26 | } 27 | 28 | if (count == 0) 29 | { 30 | break; 31 | } 32 | 33 | copy(y, y + n + 1, x); 34 | fill(y, y + n + 1, false); 35 | 36 | if (x[n]) 37 | { 38 | maximum = step; 39 | } 40 | } 41 | printf("%d\n", maximum); 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /203A - Two Problems.cpp: -------------------------------------------------------------------------------- 1 | //4172437 Jul 27, 2013 5:48:18 AM fuwutu 203A - Two Problems GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int x, t, a, b, da, db; 9 | cin >> x >> t >> a >> b >> da >> db; 10 | if (x == 0) 11 | { 12 | cout << "YES" << endl; 13 | return 0; 14 | } 15 | 16 | if (x == 0 17 | || (x <= a && x > a - da * t && (a - x) % da == 0) 18 | || (x <= b && x > b - db * t && (b - x) % db == 0)) 19 | { 20 | cout << "YES" << endl; 21 | return 0; 22 | } 23 | 24 | for (int pa = a, pb = b - db * (t - 1); pa > a - da * t && pb <= b; ) 25 | { 26 | if (pa + pb > x) 27 | { 28 | pa -= da; 29 | } 30 | else if (pa + pb < x) 31 | { 32 | pb += db; 33 | } 34 | else 35 | { 36 | cout << "YES" << endl; 37 | return 0; 38 | } 39 | } 40 | cout << "NO" << endl; 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /161A - Dress'em in Vests!.cpp: -------------------------------------------------------------------------------- 1 | //4172027 Jul 27, 2013 4:39:57 AM fuwutu 161A - Dress'em in Vests! GNU C++0x Accepted 342 ms 800 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, m, x, y, a[100000], b[100000]; 9 | scanf("%d%d%d%d", &n, &m, &x, &y); 10 | for (int i = 0; i < n; ++i) 11 | { 12 | scanf("%d", &a[i]); 13 | } 14 | for (int j = 0; j < m; ++j) 15 | { 16 | scanf("%d", &b[j]); 17 | } 18 | 19 | int count(0); 20 | for (int i = 0, j = 0; i < n && j < m; ) 21 | { 22 | if (b[j] < a[i] - x) 23 | { 24 | ++j; 25 | } 26 | else if (b[j] > a[i] + y) 27 | { 28 | ++i; 29 | } 30 | else 31 | { 32 | a[count] = ++i; 33 | b[count] = ++j; 34 | ++count; 35 | } 36 | } 37 | 38 | printf("%d\n", count); 39 | for (int k = 0; k < count; ++k) 40 | { 41 | printf("%d %d\n", a[k], b[k]); 42 | } 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /152A - Marks.cpp: -------------------------------------------------------------------------------- 1 | //4034103 Jul 7, 2013 1:39:50 PM fuwutu 152A - Marks GNU C++0x Accepted 15 ms 100 KB 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | int main() 10 | { 11 | size_t n, m; 12 | cin >> n >> m; 13 | vector marks(n); 14 | for (size_t i = 0; i < n; ++i) 15 | { 16 | cin >> marks[i]; 17 | } 18 | vector successful(n, false); 19 | for (size_t subject = 0; subject < m; ++subject) 20 | { 21 | char best = '0'; 22 | for (size_t i = 0; i < n; ++i) 23 | { 24 | if (marks[i][subject] > best) 25 | { 26 | best = marks[i][subject]; 27 | } 28 | } 29 | for (size_t i = 0; i < n; ++i) 30 | { 31 | if (marks[i][subject] == best) 32 | { 33 | successful[i] = true; 34 | } 35 | } 36 | } 37 | cout << count(successful.begin(), successful.end(), true); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /218B - Airport.cpp: -------------------------------------------------------------------------------- 1 | //4057689 Jul 13, 2013 7:39:37 AM fuwutu 218B - Airport GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int n, m, a[1000]; 10 | cin >> n >> m; 11 | for (int i = 0; i < m; ++i) 12 | { 13 | cin >> a[i]; 14 | } 15 | 16 | sort(a, a + m); 17 | int minimum(0), num(a[0]), k(0); 18 | for (int i = 0; i < n; ++i) 19 | { 20 | minimum += num; 21 | num -= 1; 22 | if (num == 0) 23 | { 24 | num = a[++k]; 25 | } 26 | } 27 | 28 | sort(a, a + m, greater()); 29 | int maximum(0); 30 | while (n--) 31 | { 32 | maximum += a[0]; 33 | a[0] -= 1; 34 | for (int i = 1; i < m; ++i) 35 | { 36 | if (a[i] <= a[i-1]) 37 | { 38 | break; 39 | } 40 | swap(a[i], a[i-1]); 41 | } 42 | } 43 | 44 | cout << maximum << " " << minimum << endl; 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /317A - Perfect Pair.cpp: -------------------------------------------------------------------------------- 1 | //4231314 Aug 5, 2013 9:18:30 AM fuwutu 317A - Perfect Pair GNU C++0x Accepted 62 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | long long x, y, m; 10 | cin >> x >> y >> m; 11 | if (x >= m || y >= m) 12 | { 13 | cout << 0 << endl; 14 | } 15 | else 16 | { 17 | if (x <= 0 && y <= 0) 18 | { 19 | cout << -1 << endl; 20 | } 21 | else 22 | { 23 | if (x < y) 24 | { 25 | swap(x, y); 26 | } 27 | long long result(0); 28 | if (y < 0) 29 | { 30 | long long n = (-y) / x + 1; 31 | result += n; 32 | y += x * n; 33 | } 34 | while (x < m) 35 | { 36 | y += x; 37 | swap(x, y); 38 | result += 1; 39 | } 40 | cout << result << endl; 41 | } 42 | } 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /166A - Rank List.cpp: -------------------------------------------------------------------------------- 1 | //4042740 Jul 9, 2013 6:04:04 PM fuwutu 166A - Rank List GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | struct team 8 | { 9 | int problems; 10 | int penaltytime; 11 | }; 12 | 13 | bool cmp(const team& left, const team& right) 14 | { 15 | return left.problems > right.problems 16 | || (left.problems == right.problems && left.penaltytime < right.penaltytime); 17 | } 18 | 19 | int main() 20 | { 21 | int n, k; 22 | team t[50]; 23 | cin >> n >> k; 24 | for (int i = 0; i < n; ++i) 25 | { 26 | cin >> t[i].problems >> t[i].penaltytime; 27 | } 28 | sort(t, t + n, cmp); 29 | k -= 1; 30 | int l(k), r(k); 31 | while (l > 0 && t[l-1].problems == t[k].problems && t[l-1].penaltytime == t[k].penaltytime) 32 | { 33 | l -= 1; 34 | } 35 | while (r + 1 < n && t[r+1].problems == t[k].problems && t[r+1].penaltytime == t[k].penaltytime) 36 | { 37 | r += 1; 38 | } 39 | cout << r - l + 1 << endl; 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /287A - IQ Test.cpp: -------------------------------------------------------------------------------- 1 | //4034464 Jul 7, 2013 3:07:20 PM fuwutu 287A - IQ Test GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | vector vs(4); 11 | for (size_t i = 0; i < 4; ++i) 12 | { 13 | cin >> vs[i]; 14 | } 15 | 16 | bool pass = false; 17 | for (size_t top = 0; top <= 2 && !pass; ++top) 18 | { 19 | for (size_t left = 0; left <= 2; ++left) 20 | { 21 | int dot = 0; 22 | for (size_t r = 0; r < 2; ++r) 23 | { 24 | for (size_t c = 0; c < 2; ++c) 25 | { 26 | if (vs[top+r][left+c] == '.') 27 | { 28 | dot += 1; 29 | } 30 | } 31 | } 32 | if (dot != 2) 33 | { 34 | pass = true; 35 | break; 36 | } 37 | } 38 | } 39 | cout << (pass ? "YES" : "NO") << endl; 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /230B - T-primes.cpp: -------------------------------------------------------------------------------- 1 | //4048435 Jul 11, 2013 3:30:44 AM fuwutu 230B - T-primes GNU C++0x Accepted 78 ms 3100 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | bool notprime[1000000] = {false}; 10 | for (int i = 3; i < 1000; i += 2) 11 | { 12 | if (!notprime[i]) 13 | { 14 | int ii = i + i; 15 | for (int j = i + ii; j < 1000000; j += ii) 16 | { 17 | notprime[j] = true; 18 | } 19 | } 20 | } 21 | vector t_primes; 22 | t_primes.push_back(2*2); 23 | for (int i = 3; i < 1000000; i += 2) 24 | { 25 | if (!notprime[i]) 26 | { 27 | t_primes.push_back(static_cast(i) * static_cast(i)); 28 | } 29 | } 30 | int n; 31 | scanf("%d", &n); 32 | while (n--) 33 | { 34 | long long x; 35 | scanf("%I64d", &x); 36 | printf("%s\n", binary_search(t_primes.begin(), t_primes.end(), x) ? "YES" : "NO"); 37 | } 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /222B - Cosmic Tables.cpp: -------------------------------------------------------------------------------- 1 | //4236807 Aug 6, 2013 4:09:16 PM fuwutu 222B - Cosmic Tables GNU C++0x Accepted 872 ms 3900 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int p[1001][1001], row[1001], col[1001]; 8 | 9 | int main() 10 | { 11 | int n, m, k; 12 | scanf("%d%d%d", &n, &m, &k); 13 | 14 | for (int r = 1; r <= n; ++r) 15 | row[r] = r; 16 | 17 | for (int c = 1; c <= m; ++c) 18 | col[c] = c; 19 | 20 | for (int r = 1; r <= n; ++r) 21 | for (int c = 1; c <= m; ++c) 22 | scanf("%d", &p[r][c]); 23 | 24 | while (k--) 25 | { 26 | char s[2]; 27 | int x, y; 28 | scanf("%s%d%d", s, &x, &y); 29 | switch (s[0]) 30 | { 31 | case 'r': 32 | swap(row[x], row[y]); 33 | break; 34 | case 'c': 35 | swap(col[x], col[y]); 36 | break; 37 | case 'g': 38 | printf("%d\n", p[row[x]][col[y]]); 39 | break; 40 | default: 41 | break; 42 | } 43 | } 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /133B - Unary.cpp: -------------------------------------------------------------------------------- 1 | //4136816 Jul 22, 2013 9:05:14 PM fuwutu 133B - Unary GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | int main() 5 | { 6 | char p[101]; 7 | scanf("%s", p); 8 | int size(0); 9 | for (size_t i = 0; p[i] != 0; ++i) 10 | { 11 | size *= 16; 12 | switch (p[i]) 13 | { 14 | case '>': 15 | size += 8; 16 | break; 17 | 18 | case '<': 19 | size += 9; 20 | break; 21 | 22 | case '+': 23 | size += 10; 24 | break; 25 | 26 | case '-': 27 | size += 11; 28 | break; 29 | 30 | case '.': 31 | size += 12; 32 | break; 33 | 34 | case ',': 35 | size += 13; 36 | break; 37 | 38 | case '[': 39 | size += 14; 40 | break; 41 | 42 | case ']': 43 | size += 15; 44 | break; 45 | 46 | default: 47 | break; 48 | } 49 | 50 | size %= 1000003; 51 | } 52 | printf("%d\n", size); 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /221B - Little Elephant and Numbers.cpp: -------------------------------------------------------------------------------- 1 | //4263403 Aug 11, 2013 5:31:52 AM fuwutu 221B - Little Elephant and Numbers GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | bool digit[10] = {false}; 7 | 8 | void init(int n) 9 | { 10 | while (n != 0) 11 | { 12 | digit[n % 10] = true; 13 | n /= 10; 14 | } 15 | } 16 | 17 | bool match(int n) 18 | { 19 | while (n != 0) 20 | { 21 | if (digit[n % 10]) 22 | { 23 | return true; 24 | } 25 | n /= 10; 26 | } 27 | return false; 28 | } 29 | 30 | int main() 31 | { 32 | int x; 33 | cin >> x; 34 | init(x); 35 | 36 | int d = 1, count(0); 37 | while (d * d < x) 38 | { 39 | if (x % d == 0) 40 | { 41 | if (match(d)) 42 | { 43 | ++count; 44 | } 45 | if (match(x / d)) 46 | { 47 | ++count; 48 | } 49 | } 50 | ++d; 51 | } 52 | if (d * d == x && match(d)) 53 | { 54 | ++count; 55 | } 56 | cout << count << endl; 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /334B - Eight Point Sets.cpp: -------------------------------------------------------------------------------- 1 | //4176866 Jul 27, 2013 12:50:16 PM fuwutu 334B - Eight Point Sets GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | struct point 8 | { 9 | int x; 10 | int y; 11 | }; 12 | 13 | bool cmp(const point& left, const point& right) 14 | { 15 | return (left.x < right.x) 16 | || (left.x == right.x && left.y < right.y); 17 | } 18 | 19 | int main() 20 | { 21 | point p[8]; 22 | for (int i = 0; i < 8; ++i) 23 | { 24 | cin >> p[i].x >> p[i].y; 25 | } 26 | sort(p, p + 8, cmp); 27 | if ( p[0].x == p[1].x && p[1].x == p[2].x 28 | && p[2].x != p[3].x 29 | && p[3].x == p[4].x 30 | && p[4].x != p[5].x 31 | && p[5].x == p[6].x && p[6].x == p[7].x 32 | && p[0].y == p[3].y && p[3].y == p[5].y 33 | && p[5].y != p[1].y 34 | && p[1].y == p[6].y 35 | && p[6].y != p[2].y 36 | && p[2].y == p[4].y && p[4].y == p[7].y) 37 | { 38 | cout << "respectable" << endl; 39 | } 40 | else 41 | { 42 | cout << "ugly" << endl; 43 | } 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /158D - Ice Sculptures.cpp: -------------------------------------------------------------------------------- 1 | //4030436 Jul 6, 2013 2:16:09 PM fuwutu 158D - Ice Sculptures GNU C++0x Accepted 15 ms 100 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int n, t[20000], sum(0), partsum[20000]; 10 | scanf("%d", &n); 11 | 12 | for (int i = 0; i < n; ++i) 13 | { 14 | scanf("%d", &t[i]); 15 | sum += t[i]; 16 | } 17 | 18 | int maximum(sum); 19 | for (int d = 2; d <= n / 3; ++d) 20 | { 21 | if (n % d == 0) 22 | { 23 | fill(partsum, partsum + d, 0); 24 | int x = n / d; 25 | int k = 0; 26 | for (int i = 0; i < x; ++i) 27 | { 28 | for (int j = 0; j < d; ++j) 29 | { 30 | partsum[j] += t[k++]; 31 | } 32 | } 33 | for (int j = 0; j < d; ++j) 34 | { 35 | if (partsum[j] > maximum) 36 | { 37 | maximum = partsum[j]; 38 | } 39 | } 40 | } 41 | } 42 | printf("%d\n", maximum); 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /298B - Sail.cpp: -------------------------------------------------------------------------------- 1 | //4263324 Aug 11, 2013 5:07:31 AM fuwutu 298B - Sail GNU C++0x Accepted 62 ms 300 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int t, sx, sy, ex, ey, time(-1); 10 | string wind; 11 | cin >> t >> sx >> sy >> ex >> ey >> wind; 12 | for (int i = 0; i < t; ++i) 13 | { 14 | switch (wind[i]) 15 | { 16 | case 'E': 17 | if (sx < ex) 18 | { 19 | sx += 1; 20 | } 21 | break; 22 | case 'S': 23 | if (sy > ey) 24 | { 25 | sy -= 1; 26 | } 27 | break; 28 | case 'W': 29 | if (sx > ex) 30 | { 31 | sx -= 1; 32 | } 33 | break; 34 | case 'N': 35 | if (sy < ey) 36 | { 37 | sy += 1; 38 | } 39 | break; 40 | default: 41 | break; 42 | } 43 | if (sx == ex && sy == ey) 44 | { 45 | time = i + 1; 46 | break; 47 | } 48 | } 49 | cout << time << endl; 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /316A1 - Special Task (30 points).cpp: -------------------------------------------------------------------------------- 1 | //4215774 Aug 2, 2013 10:26:21 AM fuwutu 316A1 - Special Task (30 points) GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | string s; 11 | cin >> s; 12 | 13 | int letter[128] = {0}, zero = 0; 14 | for (size_t i = 0; i < s.length(); ++i) 15 | { 16 | if (s[i] >= 'A' && s[i] < 'K') 17 | { 18 | letter[s[i]] = 1; 19 | } 20 | else if (s[i] == '?') 21 | { 22 | zero += 1; 23 | } 24 | } 25 | 26 | int result = 1; 27 | int lettercount = accumulate(letter + 'A', letter + 'K', 0); 28 | if (lettercount > 0) 29 | { 30 | if (s[0] >= 'A' && s[0] < 'K') 31 | { 32 | result *= 9; 33 | } 34 | else 35 | { 36 | result *= 10; 37 | } 38 | } 39 | for (int i = 1; i < lettercount; ++i) 40 | { 41 | result *= (10 - i); 42 | } 43 | 44 | if (zero > 0 && s[0] == '?') 45 | { 46 | result *= 9; 47 | zero -= 1; 48 | } 49 | 50 | string padding(zero, '0'); 51 | cout << result << padding << endl; 52 | } 53 | -------------------------------------------------------------------------------- /316A2 - Special Task (70 points).cpp: -------------------------------------------------------------------------------- 1 | //4215779 Aug 2, 2013 10:27:41 AM fuwutu 316A2 - Special Task (70 points) GNU C++0x Accepted 30 ms 300 KB 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | string s; 11 | cin >> s; 12 | 13 | int letter[128] = {0}, zero = 0; 14 | for (size_t i = 0; i < s.length(); ++i) 15 | { 16 | if (s[i] >= 'A' && s[i] < 'K') 17 | { 18 | letter[s[i]] = 1; 19 | } 20 | else if (s[i] == '?') 21 | { 22 | zero += 1; 23 | } 24 | } 25 | 26 | int result = 1; 27 | int lettercount = accumulate(letter + 'A', letter + 'K', 0); 28 | if (lettercount > 0) 29 | { 30 | if (s[0] >= 'A' && s[0] < 'K') 31 | { 32 | result *= 9; 33 | } 34 | else 35 | { 36 | result *= 10; 37 | } 38 | } 39 | for (int i = 1; i < lettercount; ++i) 40 | { 41 | result *= (10 - i); 42 | } 43 | 44 | if (zero > 0 && s[0] == '?') 45 | { 46 | result *= 9; 47 | zero -= 1; 48 | } 49 | 50 | string padding(zero, '0'); 51 | cout << result << padding << endl; 52 | } 53 | -------------------------------------------------------------------------------- /63A - Sinking Ship.cpp: -------------------------------------------------------------------------------- 1 | //4172301 Jul 27, 2013 5:23:55 AM fuwutu 63A - Sinking Ship GNU C++0x Accepted 30 ms 100 KB 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | int n; 11 | cin >> n; 12 | 13 | string name, status; 14 | vector rats, womenandchildren, men, captain; 15 | while (n--) 16 | { 17 | cin >> name >> status; 18 | if (status == "rat") 19 | { 20 | rats.push_back(name); 21 | } 22 | else if (status == "woman" || status == "child") 23 | { 24 | womenandchildren.push_back(name); 25 | } 26 | else if (status == "man") 27 | { 28 | men.push_back(name); 29 | } 30 | else 31 | { 32 | captain.push_back(name); 33 | } 34 | } 35 | for (auto one : rats) 36 | { 37 | cout << one << endl; 38 | } 39 | for (auto one : womenandchildren) 40 | { 41 | cout << one << endl; 42 | } 43 | for (auto one : men) 44 | { 45 | cout << one << endl; 46 | } 47 | for (auto one : captain) 48 | { 49 | cout << one << endl; 50 | } 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /79A - Bus Game.cpp: -------------------------------------------------------------------------------- 1 | //4266560 Aug 11, 2013 7:04:01 PM fuwutu 79A - Bus Game GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int x, y; 10 | cin >> x >> y; 11 | int turns = min(x / 2, y / 24); 12 | x -= 2 * turns; 13 | y -= 24 * turns; 14 | 15 | while (true) 16 | { 17 | if (x >= 2 && y >= 2) 18 | { 19 | x -= 2; 20 | y -= 2; 21 | } 22 | else if (x >= 1 && y >= 12) 23 | { 24 | x -= 1; 25 | y -= 12; 26 | } 27 | else if (y >= 22) 28 | { 29 | y -= 22; 30 | } 31 | else 32 | { 33 | cout << "Hanako" << endl; 34 | break; 35 | } 36 | 37 | if (y >= 22) 38 | { 39 | y -= 22; 40 | } 41 | else if (x >= 1 && y >= 12) 42 | { 43 | x -= 1; 44 | y -= 12; 45 | } 46 | else if (x >= 2 && y >= 2) 47 | { 48 | x -= 2; 49 | y -= 2; 50 | } 51 | else 52 | { 53 | cout << "Ciel" << endl; 54 | break; 55 | } 56 | } 57 | 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /236B - Easy Number Challenge.cpp: -------------------------------------------------------------------------------- 1 | //4306373 Aug 18, 2013 6:53:30 AM fuwutu 236B - Easy Number Challenge GNU C++0x Accepted 62 ms 0 KB 2 | #include 3 | 4 | int main() 5 | { 6 | const int primes[25] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97}; 7 | int pfc[101][25] = {0}; 8 | for (int i = 1; i <= 100; ++i) 9 | { 10 | int ii = i; 11 | for (int j = 0; ii != 1 && j < 25; ++j) 12 | { 13 | while (ii % primes[j] == 0) 14 | { 15 | pfc[i][j] += 1; 16 | ii /= primes[j]; 17 | } 18 | } 19 | } 20 | 21 | int a, b, c, answer(0); 22 | scanf("%d%d%d", &a, &b ,&c); 23 | for (int i = 1; i <= a; ++i) 24 | { 25 | for (int j = 1; j <= b; ++j) 26 | { 27 | for (int k = 1; k <= c; ++k) 28 | { 29 | int divisors = 1; 30 | for (int d = 0; d < 25; ++d) 31 | { 32 | divisors *= (1 + pfc[i][d] + pfc[j][d] + pfc[k][d]); 33 | } 34 | answer += divisors; 35 | } 36 | } 37 | } 38 | answer %= 1073741824; 39 | printf("%d\n", answer); 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /271B - Prime Matrix.cpp: -------------------------------------------------------------------------------- 1 | //4236666 Aug 6, 2013 3:27:01 PM fuwutu 271B - Prime Matrix GNU C++0x Accepted 124 ms 100 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | const size_t M = 100100; 10 | bool prime[M]; 11 | prime[0] = false; 12 | prime[1] = false; 13 | fill(prime + 2, prime + M, true); 14 | for (int i = 2; i * i < M; ++i) 15 | { 16 | if (prime[i]) 17 | { 18 | for (int j = i + i; j < M; j += i) 19 | { 20 | prime[j] = false; 21 | } 22 | } 23 | } 24 | 25 | int n, m, a, rows[500], cols[500]; 26 | scanf("%d%d", &n, &m); 27 | fill(rows, rows + n, 0); 28 | fill(cols, cols + m, 0); 29 | 30 | for (int r = 0; r < n; ++r) 31 | { 32 | for (int c = 0; c < m; ++c) 33 | { 34 | scanf("%d", &a); 35 | int x = a; 36 | while (!prime[x]) 37 | { 38 | ++x; 39 | } 40 | rows[r] += (x - a); 41 | cols[c] += (x - a); 42 | } 43 | } 44 | 45 | int min_row = *min_element(rows, rows + n); 46 | int min_col = *min_element(cols, cols + m); 47 | printf("%d\n", min(min_row, min_col)); 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /165A - Supercentral Point.cpp: -------------------------------------------------------------------------------- 1 | //4033090 Jul 7, 2013 7:51:42 AM fuwutu 165A - Supercentral Point GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n, x[200], y[200], supercentral(0); 9 | cin >> n; 10 | for (int i = 0; i < n; ++i) 11 | { 12 | cin >> x[i] >> y[i]; 13 | } 14 | 15 | for (int i = 0; i < n; ++i) 16 | { 17 | int bit = 15; 18 | for (int j = 0; j < n && bit != 0; ++j) 19 | { 20 | if (x[j] == x[i]) 21 | { 22 | if (y[j] < y[i]) 23 | { 24 | bit &= (15 - 1); 25 | } 26 | if (y[j] > y[i]) 27 | { 28 | bit &= (15 - 2); 29 | } 30 | } 31 | if (y[j] == y[i]) 32 | { 33 | if (x[j] < x[i]) 34 | { 35 | bit &= (15 - 4); 36 | } 37 | if (x[j] > x[i]) 38 | { 39 | bit &= (15 - 8); 40 | } 41 | } 42 | } 43 | if (bit == 0) 44 | { 45 | supercentral += 1; 46 | } 47 | } 48 | cout << supercentral << endl; 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /317B - Ants.cpp: -------------------------------------------------------------------------------- 1 | //4430072 Sep 8, 2013 5:45:06 AM fuwutu 317B - Ants GNU C++0x Accepted 436 ms 100 KB 2 | #include 3 | #include 4 | 5 | const int M = 64; 6 | 7 | int main() 8 | { 9 | int n, t, ants[M * 2 + 1][M * 2 + 1] = {0}, ants_temp[M * 2 + 1][M * 2 + 1]; 10 | scanf("%d%d", &n, &t); 11 | ants[M][M] = n; 12 | bool find = (n != 0); 13 | while (find) 14 | { 15 | find = false; 16 | 17 | memset(ants_temp, 0, sizeof(ants_temp)); 18 | 19 | for (int i = 0; i <= M * 2; ++i) 20 | { 21 | for (int j = 0; j <= M * 2; ++j) 22 | { 23 | if (ants[i][j] >= 4) 24 | { 25 | find = true; 26 | ants_temp[i-1][j] += ants[i][j] / 4; 27 | ants_temp[i+1][j] += ants[i][j] / 4; 28 | ants_temp[i][j-1] += ants[i][j] / 4; 29 | ants_temp[i][j+1] += ants[i][j] / 4; 30 | } 31 | ants_temp[i][j] += ants[i][j] % 4; 32 | } 33 | } 34 | 35 | memcpy(ants, ants_temp, sizeof(ants)); 36 | } 37 | 38 | while (t--) 39 | { 40 | int x, y; 41 | scanf("%d%d", &x, &y); 42 | printf("%d\n", (x >= -M && y >= - M && x <= M && y <= M) ? ants[M + x][M + y] : 0); 43 | } 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /278B - New Problem.cpp: -------------------------------------------------------------------------------- 1 | //4332589 Aug 24, 2013 4:25:09 PM fuwutu 278B - New Problem GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | int n; 8 | char ch[30]; 9 | bool exist1[26] = {false}, exist2[26][26] = {false}; 10 | 11 | scanf("%d", &n); 12 | for (int i = 0; i < n; ++i) 13 | { 14 | scanf("%s", ch); 15 | for (int j = 0; j < strlen(ch); ++j) 16 | { 17 | exist1[ch[j]-'a'] = true; 18 | } 19 | for (int j = 1; j < strlen(ch); ++j) 20 | { 21 | exist2[ch[j-1]-'a'][ch[j]-'a'] = true; 22 | } 23 | } 24 | 25 | bool found = false; 26 | for (char c = 'a'; c <= 'z'; ++c) 27 | { 28 | if (!exist1[c-'a']) 29 | { 30 | printf("%c\n", c); 31 | found = true; 32 | break; 33 | } 34 | } 35 | 36 | if (!found) 37 | { 38 | for (char c1 = 'a'; !found && c1 <= 'z'; ++c1) 39 | { 40 | for (char c2 = 'a'; c2 <= 'z'; ++c2) 41 | { 42 | if (!exist2[c1-'a'][c2-'a']) 43 | { 44 | printf("%c%c\n", c1, c2); 45 | found = true; 46 | break; 47 | } 48 | } 49 | } 50 | } 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /312A - Whose sentence is it.cpp: -------------------------------------------------------------------------------- 1 | //4263699 Aug 11, 2013 7:03:13 AM fuwutu 312A - Whose sentence is it? GNU C++0x Accepted 62 ms 100 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int n; 10 | cin >> n; 11 | 12 | char ch[101]; 13 | cin.getline(ch, 101); 14 | 15 | string s; 16 | while (n--) 17 | { 18 | cin.getline(ch, 101); 19 | s.assign(ch); 20 | 21 | if (s.length() >= 5) 22 | { 23 | if (s.substr(s.length() - 5, 5) == "lala.") 24 | { 25 | if (s.substr(0, 5) == "miao.") 26 | { 27 | cout << "OMG>.< I don't know!" << endl; 28 | } 29 | else 30 | { 31 | cout << "Freda's" << endl; 32 | } 33 | } 34 | else 35 | { 36 | if (s.substr(0, 5) == "miao.") 37 | { 38 | cout << "Rainbow's" << endl; 39 | } 40 | else 41 | { 42 | cout << "OMG>.< I don't know!" << endl; 43 | } 44 | } 45 | } 46 | else 47 | { 48 | cout << "OMG>.< I don't know!" << endl; 49 | } 50 | } 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /148A - Insomnia cure.cpp: -------------------------------------------------------------------------------- 1 | //4007107 Jul 3, 2013 7:04:01 PM fuwutu 148A - Insomnia cure GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int LCM(int m, int n) 7 | { 8 | int mm(m), nn(n), r; 9 | while ((r = m % n) != 0) 10 | { 11 | m = n; 12 | n = r; 13 | } 14 | return mm / n * nn; 15 | } 16 | 17 | int main() 18 | { 19 | int k, l, m, n, d, count(0); 20 | cin >> k >> l >> m >> n >> d; 21 | 22 | int lcm = LCM(LCM(k, l), LCM(m, n)); 23 | if (d > lcm) 24 | { 25 | int r = 0; 26 | for (int i = 1; i <= d % lcm; ++i) 27 | { 28 | if (i % k == 0 || i % l == 0 || i % m == 0 || i % n == 0) 29 | { 30 | r += 1; 31 | } 32 | } 33 | 34 | int c = r; 35 | for (int i = d % lcm + 1; i <= lcm; ++i) 36 | { 37 | if (i % k == 0 || i % l == 0 || i % m == 0 || i % n == 0) 38 | { 39 | c += 1; 40 | } 41 | } 42 | 43 | count = c * (d / lcm) + r; 44 | } 45 | else 46 | { 47 | for (int i = 1; i <= d; ++i) 48 | { 49 | if (i % k == 0 || i % l == 0 || i % m == 0 || i % n == 0) 50 | { 51 | count += 1; 52 | } 53 | } 54 | } 55 | cout << count << endl; 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /291B - Command Line Arguments.cpp: -------------------------------------------------------------------------------- 1 | //4057396 Jul 13, 2013 6:22:17 AM fuwutu 291B - Command Line Arguments GNU C++0x Accepted 62 ms 100 KB 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | char s[100001]; 9 | string lexeme; 10 | cin.getline(s, sizeof(s) / sizeof(s[0])); 11 | char* p = s; 12 | bool quote(false); 13 | while (*p != 0) 14 | { 15 | if (quote) 16 | { 17 | if (*p != '\"') 18 | { 19 | lexeme.push_back(*p); 20 | } 21 | else 22 | { 23 | cout << "<" << lexeme << ">" << endl; 24 | lexeme.clear(); 25 | quote = false; 26 | } 27 | } 28 | else 29 | { 30 | if (*p == '\"') 31 | { 32 | quote = true; 33 | } 34 | else if (*p == ' ') 35 | { 36 | if (!lexeme.empty()) 37 | { 38 | cout << "<" << lexeme << ">" << endl; 39 | lexeme.clear(); 40 | } 41 | } 42 | else 43 | { 44 | lexeme.push_back(*p); 45 | } 46 | } 47 | ++p; 48 | } 49 | if (!lexeme.empty()) 50 | { 51 | cout << "<" << lexeme << ">" << endl; 52 | } 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /166E - Tetrahedron.cpp: -------------------------------------------------------------------------------- 1 | //4324919 Aug 22, 2013 8:27:14 PM fuwutu 166E - Tetrahedron GNU C++0x Accepted 62 ms 0 KB 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | int n; 8 | scanf("%d", &n); 9 | 10 | long long a[4][4] = {{0, 1, 1, 1}, {1, 0, 1, 1}, {1, 1, 0, 1}, {1, 1, 1, 0}}; 11 | long long b[4][4] = {{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}}; 12 | while (n != 0) 13 | { 14 | if (n % 2 == 1) 15 | { 16 | long long c[4][4] = {0}; 17 | for (int i = 0; i < 4; ++i) 18 | { 19 | for (int j = 0; j < 4; ++j) 20 | { 21 | for (int k = 0; k < 4; ++k) 22 | { 23 | c[i][j] += a[i][k] * b[k][j]; 24 | } 25 | c[i][j] %= 1000000007LL; 26 | } 27 | } 28 | memcpy(b, c, sizeof(b)); 29 | } 30 | 31 | long long c[4][4] = {0}; 32 | for (int i = 0; i < 4; ++i) 33 | { 34 | for (int j = 0; j < 4; ++j) 35 | { 36 | for (int k = 0; k < 4; ++k) 37 | { 38 | c[i][j] += a[i][k] * a[k][j]; 39 | } 40 | c[i][j] %= 1000000007LL; 41 | } 42 | } 43 | memcpy(a, c, sizeof(a)); 44 | 45 | n /= 2; 46 | } 47 | 48 | printf("%I64d\n", b[0][0]); 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /284A - Cows and Primitive Roots.cpp: -------------------------------------------------------------------------------- 1 | //4306626 Aug 18, 2013 8:16:30 AM fuwutu 284A - Cows and Primitive Roots GNU C++0x Accepted 62 ms 0 KB 2 | #include 3 | 4 | int main() 5 | { 6 | int p, count(0); 7 | scanf("%d", &p); 8 | for (int n = 1; n < p; ++n) 9 | { 10 | bool ok = true; 11 | int x = 1; 12 | for (int i = 1; i < p - 1; ++i) 13 | { 14 | x *= n; 15 | x %= p; 16 | if (x == 1) 17 | { 18 | ok = false; 19 | break; 20 | } 21 | } 22 | if (ok) 23 | { 24 | x *= n; 25 | x %= p; 26 | if (x == 1) 27 | { 28 | count += 1; 29 | } 30 | } 31 | } 32 | printf("%d\n", count); 33 | return 0; 34 | } 35 | 36 | 37 | //4306655 Aug 18, 2013 8:36:13 AM fuwutu 284A - Cows and Primitive Roots GNU C++0x Accepted 30 ms 0 KB 38 | #include 39 | 40 | int main() 41 | { 42 | int p; 43 | scanf("%d", &p); 44 | int n = p - 1; 45 | int count = n; 46 | for (int i = 2; i * i <= n; ++i) 47 | { 48 | if (n % i == 0) 49 | { 50 | do 51 | { 52 | n /= i; 53 | } while (n % i == 0); 54 | count = count / i * (i - 1); 55 | } 56 | } 57 | if (n != 1) 58 | { 59 | count = count / n * (n - 1); 60 | } 61 | printf("%d\n", count); 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /336C - Vasily the Bear and Sequence.cpp: -------------------------------------------------------------------------------- 1 | //4331596 Aug 24, 2013 12:22:08 PM fuwutu 336C - Vasily the Bear and Sequence GNU C++0x Accepted 124 ms 400 KB 2 | #include 3 | 4 | int main() 5 | { 6 | int n, a[100000], count[32] = {0}; 7 | bool b[32][32] = {false}; 8 | scanf("%d", &n); 9 | for (int i = 0; i < n; ++i) 10 | { 11 | scanf("%d", &a[i]); 12 | int x = a[i], index = 0, zero[32], zerocount = 0; 13 | while (x != 0) 14 | { 15 | if (x % 2 == 1) 16 | { 17 | count[index] += 1; 18 | for (int j = 0; j < zerocount; ++j) 19 | { 20 | b[index][zero[j]] = true; 21 | } 22 | } 23 | else 24 | { 25 | zero[zerocount++] = index; 26 | } 27 | x /= 2; 28 | index += 1; 29 | } 30 | } 31 | 32 | int v = 31; 33 | for (;;) 34 | { 35 | int j = 0; 36 | for (; j < v; ++j) 37 | { 38 | if (!b[v][j]) 39 | { 40 | break; 41 | } 42 | } 43 | if (j == v) 44 | { 45 | break; 46 | } 47 | --v; 48 | } 49 | int k = count[v]; 50 | printf("%d\n", k); 51 | 52 | int pv = 1 << v; 53 | for (int i = 0; i < n; ++i) 54 | { 55 | if ((a[i] & pv) != 0) 56 | { 57 | printf((--k != 0 ? "%d " : "%d\n"), a[i]); 58 | } 59 | } 60 | 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /2A - Winner.cpp: -------------------------------------------------------------------------------- 1 | //4192132 Jul 28, 2013 4:38:27 AM fuwutu 2A - Winner GNU C++0x Accepted 30 ms 200 KB 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | int main() 11 | { 12 | int n; 13 | cin >> n; 14 | 15 | vector> rounds(n); 16 | map player2score; 17 | for (int i = 0; i < n; ++i) 18 | { 19 | cin >> rounds[i].first >> rounds[i].second; 20 | player2score[rounds[i].first] += rounds[i].second; 21 | } 22 | 23 | set winners; 24 | int m(-1000001); 25 | for (map::iterator it = player2score.begin(); it != player2score.end(); ++it) 26 | { 27 | if (it->second > m) 28 | { 29 | m = it->second; 30 | winners.clear(); 31 | winners.insert(it->first); 32 | } 33 | else if (it->second == m) 34 | { 35 | winners.insert(it->first); 36 | } 37 | } 38 | 39 | if (winners.size() > 1) 40 | { 41 | player2score.clear(); 42 | for (vector>::iterator it = rounds.begin(); it != rounds.end(); ++it) 43 | { 44 | player2score[it->first] += it->second; 45 | if (player2score[it->first] >= m && winners.count(it->first) == 1) 46 | { 47 | winners.clear(); 48 | winners.insert(it->first); 49 | break; 50 | } 51 | } 52 | } 53 | 54 | cout << *winners.begin() << endl; 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /300A - Array.cpp: -------------------------------------------------------------------------------- 1 | //4034291 Jul 7, 2013 2:22:31 PM fuwutu 300A - Array GNU C++0x Accepted 15 ms 0 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int n; 10 | cin >> n; 11 | 12 | vector arr(n); 13 | for (int i = 0; i < n; ++i) 14 | { 15 | cin >> arr[i]; 16 | } 17 | 18 | for (vector::iterator it = arr.begin(); it != arr.end(); ++it) 19 | { 20 | if (*it < 0) 21 | { 22 | cout << "1 " << *it << endl; 23 | arr.erase(it); 24 | break; 25 | } 26 | } 27 | 28 | bool found(false); 29 | for (vector::iterator it = arr.begin(); it != arr.end(); ++it) 30 | { 31 | if (*it > 0) 32 | { 33 | found = true; 34 | cout << "1 " << *it << endl; 35 | arr.erase(it); 36 | break; 37 | } 38 | } 39 | 40 | if (!found) 41 | { 42 | cout << "2"; 43 | int count = 0; 44 | for (vector::iterator it = arr.begin(); count < 2;) 45 | { 46 | if (*it < 0) 47 | { 48 | cout << " " << *it; 49 | it = arr.erase(it); 50 | ++count; 51 | } 52 | else 53 | { 54 | ++it; 55 | } 56 | } 57 | cout << endl; 58 | } 59 | 60 | cout << arr.size(); 61 | for (size_t i = 0; i < arr.size(); ++i) 62 | { 63 | cout << " " << arr[i]; 64 | } 65 | cout << endl; 66 | 67 | return 0; 68 | } 69 | -------------------------------------------------------------------------------- /1B - Spreadsheet.cpp: -------------------------------------------------------------------------------- 1 | //4034419 Jul 7, 2013 2:54:03 PM fuwutu 1B - Spreadsheet GNU C++0x Accepted 109 ms 0 KB 2 | #include 3 | #include 4 | #include 5 | 6 | int main() 7 | { 8 | int n; 9 | char ch[20]; 10 | scanf("%d", &n); 11 | while (n--) 12 | { 13 | scanf("%s", ch); 14 | size_t m = strlen(ch); 15 | size_t C = 1; 16 | while (C < m && isdigit(ch[C])) 17 | { 18 | ++C; 19 | } 20 | 21 | if (C > 1 && C < m) 22 | { 23 | int col(0); 24 | for (size_t i = C + 1; i < m; ++i) 25 | { 26 | col = col * 10 + (ch[i] - '0'); 27 | } 28 | 29 | int pow(26); 30 | while (col > pow) 31 | { 32 | col -= pow; 33 | pow *= 26; 34 | } 35 | 36 | col -= 1; 37 | while (pow != 1) 38 | { 39 | pow /= 26; 40 | printf("%c", col / pow + 'A'); 41 | col %= pow; 42 | } 43 | 44 | ch[C] = 0; 45 | printf("%s\n", ch + 1); 46 | } 47 | else 48 | { 49 | int col(0), val(0), pow = (1); 50 | size_t i = 0; 51 | while (isalpha(ch[i])) 52 | { 53 | col += pow; 54 | pow *= 26; 55 | val = val * 26 + ch[i] - 'A'; 56 | i += 1; 57 | } 58 | col += val; 59 | printf("R%sC%d\n", ch + i, col); 60 | } 61 | } 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /335A - Banana.cpp: -------------------------------------------------------------------------------- 1 | //4331873 Aug 24, 2013 1:46:14 PM fuwutu 335A - Banana GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | char s[1000]; 8 | int n, count1[128] = {0}, count2[128] = {0}; 9 | 10 | scanf("%s%d", s, &n); 11 | for (int i = 0; i < strlen(s); ++i) 12 | { 13 | count1[s[i]] += 1; 14 | } 15 | 16 | int letters = 0; 17 | for (int i = 'a'; i <= 'z'; ++i) 18 | { 19 | if (count1[i] != 0) 20 | { 21 | letters += 1; 22 | } 23 | } 24 | 25 | if (letters <= n) 26 | { 27 | while (n--) 28 | { 29 | int numerator = 1001, denominator = 1, index = 0; 30 | for (int i = 'a'; i <= 'z'; ++i) 31 | { 32 | if (count1[i] != 0) 33 | { 34 | if (count2[i] * denominator < numerator * count1[i]) 35 | { 36 | numerator = count2[i]; 37 | denominator = count1[i]; 38 | index = i; 39 | } 40 | } 41 | } 42 | count2[index] += 1; 43 | } 44 | 45 | int sheets = 0; 46 | for (int i = 'a'; i <= 'z'; ++i) 47 | { 48 | if (count2[i] != 0) 49 | { 50 | int temp = (count1[i] + count2[i] - 1) / count2[i]; 51 | if (temp > sheets) 52 | { 53 | sheets = temp; 54 | } 55 | } 56 | } 57 | printf("%d\n", sheets); 58 | 59 | for (int i = 'a'; i <= 'z'; ++i) 60 | { 61 | while (count2[i]--) 62 | { 63 | printf("%c", i); 64 | } 65 | } 66 | printf("\n"); 67 | } 68 | else 69 | { 70 | printf("-1\n"); 71 | } 72 | 73 | return 0; 74 | } 75 | -------------------------------------------------------------------------------- /159B - Matchmaker.cpp: -------------------------------------------------------------------------------- 1 | //4192310 Jul 28, 2013 5:58:29 AM fuwutu 159B - Matchmaker GNU C++0x Accepted 342 ms 1500 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | struct marker 8 | { 9 | int ax; 10 | int by; 11 | }; 12 | 13 | bool cmp(const marker& left, const marker& right) 14 | { 15 | return (left.by < right.by) 16 | || (left.by == right.by && left.ax < right.ax); 17 | } 18 | 19 | int main() 20 | { 21 | marker markers[100000], caps[100000]; 22 | int n, m; 23 | scanf("%d%d", &n, &m); 24 | 25 | for (int i = 0; i < n; ++i) 26 | { 27 | scanf("%d%d", &markers[i].ax, &markers[i].by); 28 | } 29 | 30 | for (int i = 0; i < m; ++i) 31 | { 32 | scanf("%d%d", &caps[i].ax, &caps[i].by); 33 | } 34 | 35 | sort(markers, markers + n, cmp); 36 | sort(caps, caps + m, cmp); 37 | 38 | int u(0); 39 | for (int i = 0, j = 0; i < n && j < m; ) 40 | { 41 | if (markers[i].by < caps[j].by) 42 | { 43 | ++i; 44 | } 45 | else if (markers[i].by > caps[j].by) 46 | { 47 | ++j; 48 | } 49 | else 50 | { 51 | ++u; 52 | ++i; 53 | ++j; 54 | } 55 | } 56 | 57 | int v(0); 58 | for (int i = 0, j = 0; i < n && j < m; ) 59 | { 60 | if (markers[i].by < caps[j].by) 61 | { 62 | ++i; 63 | } 64 | else if (markers[i].by > caps[j].by) 65 | { 66 | ++j; 67 | } 68 | else 69 | { 70 | if (markers[i].ax < caps[j].ax) 71 | { 72 | ++i; 73 | } 74 | else if (markers[i].ax > caps[j].ax) 75 | { 76 | ++j; 77 | } 78 | else 79 | { 80 | ++v; 81 | ++i; 82 | ++j; 83 | } 84 | } 85 | } 86 | 87 | printf("%d %d\n", u, v); 88 | return 0; 89 | } 90 | -------------------------------------------------------------------------------- /254A - Cards with Numbers.cpp: -------------------------------------------------------------------------------- 1 | //4304346 Aug 17, 2013 7:38:25 PM fuwutu 254A - Cards with Numbers GNU C++0x Accepted 530 ms 4800 KB 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | freopen("input.txt", "r", stdin); 10 | freopen("output.txt", "w", stdout); 11 | 12 | int n; 13 | scanf("%d", &n); 14 | 15 | pair* x = new pair[n * 2]; 16 | for (int i = 0; i < n * 2; ++i) 17 | { 18 | scanf("%d", &x[i].first); 19 | x[i].second = i + 1; 20 | } 21 | 22 | sort(x, x + n * 2); 23 | bool possible = true; 24 | for (int i = 0; i < n * 2; i += 2) 25 | { 26 | if (x[i].first != x[i+1].first) 27 | { 28 | possible = false; 29 | break; 30 | } 31 | } 32 | 33 | if (possible) 34 | { 35 | for (int i = 0; i < n * 2; i += 2) 36 | { 37 | printf("%d %d\n", x[i].second, x[i+1].second); 38 | } 39 | } 40 | else 41 | { 42 | printf("-1\n"); 43 | } 44 | 45 | delete[] x; 46 | return 0; 47 | } 48 | 49 | 50 | //4304381 Aug 17, 2013 7:46:43 PM fuwutu 254A - Cards with Numbers GNU C++0x Accepted 404 ms 6900 KB 51 | #include 52 | #include 53 | 54 | using namespace std; 55 | 56 | int main() 57 | { 58 | freopen("input.txt", "r", stdin); 59 | freopen("output.txt", "w", stdout); 60 | 61 | int n, a; 62 | vector index[5001]; 63 | scanf("%d", &n); 64 | for (int i = 1; i <= n * 2; ++i) 65 | { 66 | scanf("%d", &a); 67 | index[a].push_back(i); 68 | } 69 | 70 | bool possible = true; 71 | for (int i = 1; i < 5001; ++i) 72 | { 73 | if (index[i].size() % 2 == 1) 74 | { 75 | possible = false; 76 | break; 77 | } 78 | } 79 | 80 | if (possible) 81 | { 82 | for (int i = 1; i < 5001; ++i) 83 | { 84 | for (size_t j = 0; j < index[i].size(); j += 2) 85 | { 86 | printf("%d %d\n", index[i][j], index[i][j+1]); 87 | } 88 | } 89 | } 90 | else 91 | { 92 | printf("-1\n"); 93 | } 94 | 95 | return 0; 96 | } 97 | -------------------------------------------------------------------------------- /158C - Cd and pwd commands.cpp: -------------------------------------------------------------------------------- 1 | //4027816 Jul 5, 2013 8:24:34 PM fuwutu 158C - Cd and pwd commands GNU C++0x Accepted 15 ms 100 KB 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | int n; 11 | string command, parameter; 12 | vector path; 13 | cin >> n; 14 | while (n--) 15 | { 16 | cin >> command; 17 | if (command.compare("pwd") == 0) 18 | { 19 | cout << "/"; 20 | for (size_t i = 0; i < path.size(); ++i) 21 | { 22 | cout << path[i] << "/"; 23 | } 24 | cout << endl; 25 | } 26 | else 27 | { 28 | cin >> parameter; 29 | size_t pos = 0; 30 | if (parameter[0] == '/') 31 | { 32 | path.clear(); 33 | pos = 1; 34 | } 35 | while (true) 36 | { 37 | size_t next_pos = parameter.find('/', pos); 38 | if (next_pos != string::npos) 39 | { 40 | string dir = parameter.substr(pos, next_pos - pos); 41 | if (dir.compare("..") != 0) 42 | { 43 | path.push_back(dir); 44 | } 45 | else 46 | { 47 | if (!path.empty()) 48 | { 49 | path.pop_back(); 50 | } 51 | } 52 | pos = next_pos + 1; 53 | } 54 | else 55 | { 56 | string dir = parameter.substr(pos, string::npos); 57 | if (dir.compare("..") != 0) 58 | { 59 | path.push_back(dir); 60 | } 61 | else 62 | { 63 | if (!path.empty()) 64 | { 65 | path.pop_back(); 66 | } 67 | } 68 | break; 69 | } 70 | } 71 | } 72 | } 73 | return 0; 74 | } 75 | -------------------------------------------------------------------------------- /337E - Divisor Tree.cpp: -------------------------------------------------------------------------------- 1 | //4300331 Aug 17, 2013 4:07:55 AM fuwutu 337E - Divisor Tree GNU C++0x Accepted 30 ms 0 KB 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | long long a[8], c[8]; 9 | int b[8] = {0}; 10 | 11 | void search(int n, int i, bool extra, int s, int& m) 12 | { 13 | if (i + 1 < n) 14 | { 15 | for (int j = i + 1; j < n; ++j) 16 | { 17 | if (c[j] % a[i] == 0) 18 | { 19 | c[j] /= a[i]; 20 | if (b[i] != 1) 21 | { 22 | search(n, i + 1, extra, s + 1, m); 23 | } 24 | else 25 | { 26 | search(n, i + 1, extra, s, m); 27 | } 28 | c[j] *= a[i]; 29 | } 30 | } 31 | if (b[i] != 1) 32 | { 33 | search(n, i + 1, true, s + b[i] + 1, m); 34 | } 35 | else 36 | { 37 | search(n, i + 1, true, s + b[i], m); 38 | } 39 | } 40 | else 41 | { 42 | if (b[n-1] != 1) 43 | { 44 | s += b[n-1] + 1; 45 | } 46 | else 47 | { 48 | s += b[n-1]; 49 | } 50 | if (extra) 51 | { 52 | s += 1; 53 | } 54 | if (s < m) 55 | { 56 | m = s; 57 | } 58 | } 59 | } 60 | 61 | int main() 62 | { 63 | int n; 64 | cin >> n; 65 | 66 | for (int i = 0; i < n; ++i) 67 | { 68 | cin >> a[i]; 69 | } 70 | sort(a, a + n); 71 | 72 | for (int i = 0; i < n; ++i) 73 | { 74 | c[i] = a[i]; 75 | long long x = a[i]; 76 | while (x % 2 == 0) 77 | { 78 | x /= 2; 79 | b[i] += 1; 80 | } 81 | for (long long j = 3; j * j <= x; j += 2) 82 | { 83 | while (x % j == 0) 84 | { 85 | x /= j; 86 | b[i] += 1; 87 | } 88 | } 89 | if (x != 1) 90 | { 91 | b[i] += 1; 92 | } 93 | } 94 | 95 | int m = accumulate(b, b + n, n + 1); 96 | search(n, 0, false, 0, m); 97 | 98 | cout << m << endl; 99 | 100 | return 0; 101 | } 102 | --------------------------------------------------------------------------------