SGU150-159 Solution更好的阅读体验戳此进入题面链接230. Weighings题面ExamplesSolutionCode231. Prime Sum题面ExamplesSolutionCode232. Infinite Fraction题面ExamplesSolutionCode233. The Greatest Angle题面题面SolutionCode题面SolutionCode题面SolutionCode题面SolutionCode题面SolutionCode题面SolutionCodeUPD
存在 No solution
。
Input_1
xxxxxxxxxx
313 2
22 1
31 3
Output_1
xxxxxxxxxx
112 1 3
很显然的一个拓朴排序,没什么可说的。
xxxxxxxxxx
711
2
3
4
5
6
7
8
9
10
11using namespace std;
12
13mt19937 rnd(random_device{}());
14int rndd(int l, int r){return rnd() % (r - l + 1) + l;}
15bool rnddd(int x){return rndd(1, 100) <= x;}
16
17typedef unsigned int uint;
18typedef unsigned long long unll;
19typedef long long ll;
20typedef long double ld;
21
22template < typename T = int >
23inline T read(void);
24
25int N, M;
26struct Edge{
27 Edge* nxt;
28 int to;
29 OPNEW;
30}ed[21000];
31ROPNEW(ed);
32Edge* head[110];
33int ind[110];
34int ans[110];
35int cnt(0);
36
37int main(){
38 N = read(), M = read();
39 while(M--){
40 int s = read(), t = read();
41 head[s] = new Edge{head[s], t};
42 ++ind[t];
43 }queue < int > cur;
44 for(int i = 1; i <= N; ++i)if(!ind[i])cur.push(i);
45 while(!cur.empty()){
46 int p = cur.front(); cur.pop();
47 // ans[++cnt] = p;
48 ans[p] = ++cnt;
49 for(auto i = head[p]; i; i = i->nxt)
50 if(!--ind[SON])cur.push(SON);
51 }if(cnt < N)printf("No solution\n"), exit(0);
52 for(int i = 1; i <= N; ++i)printf("%d%c", ans[i], i == N ? '\n' : ' ');
53 fprintf(stderr, "Time: %.6lf\n", (double)clock() / CLOCKS_PER_SEC);
54 return 0;
55}
56
57template < typename T >
58inline T read(void){
59 T ret(0);
60 int flag(1);
61 char c = getchar();
62 while(c != '-' && !isdigit(c))c = getchar();
63 if(c == '-')flag = -1, c = getchar();
64 while(isdigit(c)){
65 ret *= 10;
66 ret += int(c - '0');
67 c = getchar();
68 }
69 ret *= flag;
70 return ret;
71}
求
Input_1
xxxxxxxxxx
114
Output_1
xxxxxxxxxx
110
发现质数除了
xxxxxxxxxx
621
2
3
4
5
6
7
8
9
10
11using namespace std;
12
13mt19937 rnd(random_device{}());
14int rndd(int l, int r){return rnd() % (r - l + 1) + l;}
15bool rnddd(int x){return rndd(1, 100) <= x;}
16
17typedef unsigned int uint;
18typedef unsigned long long unll;
19typedef long long ll;
20typedef long double ld;
21
22template < typename T = int >
23inline T read(void);
24
25int N;
26bool notPrime[1100000];
27basic_string < int > Prime;
28struct MyPair{int x, y;};
29basic_string < MyPair > ans;
30
31int main(){
32 N = read();
33 for(int i = 2; i <= N + 10; ++i){
34 if(!notPrime[i])Prime += i;
35 for(auto p : Prime){
36 if(p * i > 1010000)break;
37 notPrime[p * i] = true;
38 if(p % i == 0)break;
39 }
40 }
41 for(auto p : Prime)if(p + 2 <= N && !notPrime[p + 2])ans += MyPair{2, p};
42 printf("%d\n", (int)ans.size());
43 for(auto p : ans)printf("%d %d\n", p.x, p.y);
44 fprintf(stderr, "Time: %.6lf\n", (double)clock() / CLOCKS_PER_SEC);
45 return 0;
46}
47
48template < typename T >
49inline T read(void){
50 T ret(0);
51 int flag(1);
52 char c = getchar();
53 while(c != '-' && !isdigit(c))c = getchar();
54 if(c == '-')flag = -1, c = getchar();
55 while(isdigit(c)){
56 ret *= 10;
57 ret += int(c - '0');
58 c = getchar();
59 }
60 ret *= flag;
61 return ret;
62}
给定
Input_1
xxxxxxxxxx
213 2
2194
Output_1
xxxxxxxxxx
11914
Input_2
xxxxxxxxxx
212 1
257
Output_2
xxxxxxxxxx
1175
Input_3
xxxxxxxxxx
214 1
20000
Output_3
xxxxxxxxxx
110000
感觉这玩意有点像 X-mouse 那道题,不难发现一共有
xxxxxxxxxx
701
2
3
4
5
6
7
8
9
10
11using namespace std;
12
13mt19937 rnd(random_device{}());
14int rndd(int l, int r){return rnd() % (r - l + 1) + l;}
15bool rnddd(int x){return rndd(1, 100) <= x;}
16
17typedef unsigned int uint;
18typedef unsigned long long unll;
19typedef long long ll;
20typedef long double ld;
21
22
23
24template < typename T = int >
25inline T read(void);
26
27int N, K;
28string S;
29string ans("");
30
31int main(){
32 N = read(), K = read();
33 cin >> S;
34 int tot = __gcd(N, K), loop = N / tot;
35 for(int s = 0; s < tot; ++s){
36 string cur;
37 cur += S.at(s);
38 for(int tmp = (s + K) % N; tmp != s; tmp = (tmp + K) % N)cur += S.at(tmp);
39 int i = 0, j = 1, k = 0;
40 while(i < loop && j < loop && k < loop){
41 char ci = cur.at((i + k) % loop), cj = cur.at((j + k) % loop);
42 if(ci == cj)++k;
43 else{
44 ci > cj ? j = j + k + 1 : i = i + k + 1;
45 if(i == j)++j;
46 k = 0;
47 }
48 }ans = max(ans, cur.substr(min(i, j), loop - min(i, j) + 1) + cur.substr(0, min(i, j)));
49 }string rans;
50 while(tot--)rans += ans;
51 cout << rans << endl;
52 fprintf(stderr, "Time: %.6lf\n", (double)clock() / CLOCKS_PER_SEC);
53 return 0;
54}
55
56template < typename T >
57inline T read(void){
58 T ret(0);
59 int flag(1);
60 char c = getchar();
61 while(c != '-' && !isdigit(c))c = getchar();
62 if(c == '-')flag = -1, c = getchar();
63 while(isdigit(c)){
64 ret *= 10;
65 ret += int(c - '0');
66 c = getchar();
67 }
68 ret *= flag;
69 return ret;
70}
阴间计算几何,跳!
xxxxxxxxxx
11
xxxxxxxxxx
11
xxxxxxxxxx
11
xxxxxxxxxx
11
xxxxxxxxxx
11
xxxxxxxxxx
11
update-2022_12_16 初稿