//題目的限制條件是每次選翻轉的區間只能更靠右,所以不能用長度為2的區間翻轉兩次達到把x翻到后面。所以確定k的方法是從左到右找到第一個順序不對的數字,然后看它的位置和現在位置的距離,因為它一定是由一個這么大的區間翻過來的。 //接下來就按照給定的k去翻,直到不成立為止 #include using namespace std; const int maxn = 100010; int n, a[maxn], pos[maxn]; int main(){ ios::sync_with_stdio(false); cin>>n; for(int i = 1; i <= n; i++){ cin>>a[i]; pos[a[i]] = i; } int k = 0; for(int i = 1; i <= n; i++) if(pos[i]-i!=0){k=pos[i]-i; break;} for(int i = 1; i <= n; i++){ if(a[i]==i)continue; if(a[i+k]!=i){ cout<<"no"; return 0; } reverse(a+i,a+pos[i]+1); } cout<<"yes\n"<
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
#include using namespace std; int gcd(int a, int b){return !b?a:gcd(b,a%b);} int main(){ int n; cin>>n; for(int i = 1; i <= n; i++){ bool x; if(i%2==1)x = 0; else x = 1; for(int j = 1; j <= n; j++){ cout<1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include using namespace std; typedef long long LL; const int maxn = 4e6+10; const LL mod = 1e9+7; bitsetp; LL pows[11] = {1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000,10000000000}; LL ma[maxn]; int main(){ ios::sync_with_stdio(false); int n; cin>>n; //mapma; //mapma; for(int i = 2; i <= n; i++){ if(p[i])continue; //ma[i] = to_string(i); ma[i] = i; for(int j = 2*i; j <= n; j+=i){ p[j] = 1; int k = 0, kk = i; while(kk > 0){k++; kk /= 10;} int t = j; while(t%i==0){ //ma[j] += to_string(i); ma[j] = (ma[j]*pows[k]%mod+i)%mod; t /= i; } } } LL ans = 0; //for(auto i : ma){ for(int i = 2; i <= n; i++){ //cout<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
//不能組成三角形不就好了?? #include using namespace std; typedef long long LL; int f[110]; int main(){ int n; cin>>n; f[0] = 1; f[1] = 2; cout<<"2 "; for(int i = 2; i <= min(40,n); i++){ f[i] = f[i-1]+f[i-2]; cout<1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。