#include <vector> #include <list> #include <map> #include <set> #include <queue> #include <list> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> using namespace std; #define FOR(i,n) for(int i=0;i<n;++i) #define FORB(i,b,n) for(int i=b;i<n;++i) #define REV(i,n) for(int i=n;i>=0;--i) #define FOREACH(T, it, v) for(T::iterator it = v.begin(); it !=v.end(); ++it) typedef unsigned int u32; typedef unsigned int uint; const int INF = (0u - 11) / 2; typedef long long ll; typedef set<int> SI; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<long long> VL; typedef set<long long> SL; typedef map<int, int> MII; int DEBUG = 1; #define print(STRING,INT) printf("%s= %d\n", STRING, INT) #define scan(INT) scanf("%d", &INT) void log(char* S, int a) { if (DEBUG) { print(S, a); } } const int MAX_SHORT = 65536; const int MEMORY_SECTOR_SIZE = 1000012; int Win[MEMORY_SECTOR_SIZE]; int Draw[MEMORY_SECTOR_SIZE]; void zadanieKAR() { int N, M; int a, b; char c; bool win = false; scan(N); scan(M); FOR(i, N + 1) { Win[i] = 0; Draw[i] = 0; } FOR(i, M) { scanf("%d %c %d", &a, &c, &b); if (c == '>') { Win[b]++; if (Win[b] == N) { win = true; } } else { Draw[b]++; } } if (win) { printf("WYGRANA\n"); return; } FORB(i, 1, N + 1) { if (Draw[i] == 0) { printf("REMIS\n"); return; } } printf("PRZEGRANA\n"); } void zadanie2B() { int n; int tab[132]; int len = 0; scan(n); if (n == 1) { printf("1\n"); return; } while (n > 0) { tab[len++] = n & 1; n >>= 1; } string S; string for1 = "*(1+(1+1)"; string for0 = "*(1+1)"; if (tab[0] == 1) { S = "1+(1+1)"; } else { S = "(1+1)"; } int bracketToClose = 0; FORB(i, 1, len - 1) { if (tab[i] == 1) { S += for1; bracketToClose++; } else { S += for0; } } FOR(i, bracketToClose) { S += ")"; } printf("%s\n", S.c_str()); } int main1A() { //int nodes = NumberOfNodes(); int n; scan(n); FOR(i, n) { zadanieKAR(); } //printf("%d\n", out); return 0; } int main1B() { int n; int t; scan(n); n = 1 << n; scan(t); vector<int> V(n, 0); FOR(i, n) { scan(V[i]); } if (t & 0x1) { std::reverse(V.begin(), V.end()); } FOR(i, n) { printf("%d ", V[i]); } printf("\n"); return 0; } int main2B() { int n; scan(n); FOR(i, n) { zadanie2B(); } return 0; } int main() { main2B(); return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | #include <vector> #include <list> #include <map> #include <set> #include <queue> #include <list> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> using namespace std; #define FOR(i,n) for(int i=0;i<n;++i) #define FORB(i,b,n) for(int i=b;i<n;++i) #define REV(i,n) for(int i=n;i>=0;--i) #define FOREACH(T, it, v) for(T::iterator it = v.begin(); it !=v.end(); ++it) typedef unsigned int u32; typedef unsigned int uint; const int INF = (0u - 11) / 2; typedef long long ll; typedef set<int> SI; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<long long> VL; typedef set<long long> SL; typedef map<int, int> MII; int DEBUG = 1; #define print(STRING,INT) printf("%s= %d\n", STRING, INT) #define scan(INT) scanf("%d", &INT) void log(char* S, int a) { if (DEBUG) { print(S, a); } } const int MAX_SHORT = 65536; const int MEMORY_SECTOR_SIZE = 1000012; int Win[MEMORY_SECTOR_SIZE]; int Draw[MEMORY_SECTOR_SIZE]; void zadanieKAR() { int N, M; int a, b; char c; bool win = false; scan(N); scan(M); FOR(i, N + 1) { Win[i] = 0; Draw[i] = 0; } FOR(i, M) { scanf("%d %c %d", &a, &c, &b); if (c == '>') { Win[b]++; if (Win[b] == N) { win = true; } } else { Draw[b]++; } } if (win) { printf("WYGRANA\n"); return; } FORB(i, 1, N + 1) { if (Draw[i] == 0) { printf("REMIS\n"); return; } } printf("PRZEGRANA\n"); } void zadanie2B() { int n; int tab[132]; int len = 0; scan(n); if (n == 1) { printf("1\n"); return; } while (n > 0) { tab[len++] = n & 1; n >>= 1; } string S; string for1 = "*(1+(1+1)"; string for0 = "*(1+1)"; if (tab[0] == 1) { S = "1+(1+1)"; } else { S = "(1+1)"; } int bracketToClose = 0; FORB(i, 1, len - 1) { if (tab[i] == 1) { S += for1; bracketToClose++; } else { S += for0; } } FOR(i, bracketToClose) { S += ")"; } printf("%s\n", S.c_str()); } int main1A() { //int nodes = NumberOfNodes(); int n; scan(n); FOR(i, n) { zadanieKAR(); } //printf("%d\n", out); return 0; } int main1B() { int n; int t; scan(n); n = 1 << n; scan(t); vector<int> V(n, 0); FOR(i, n) { scan(V[i]); } if (t & 0x1) { std::reverse(V.begin(), V.end()); } FOR(i, n) { printf("%d ", V[i]); } printf("\n"); return 0; } int main2B() { int n; scan(n); FOR(i, n) { zadanie2B(); } return 0; } int main() { main2B(); return 0; } |