2021牛客寒假算法基础集训营2,签到题FHIJ

网友投稿 647 2022-05-29

//题目的限制条件是每次选翻转的区间只能更靠右,所以不能用长度为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

2021牛客寒假算法基础集训营2,签到题FHIJ

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小时内删除侵权内容。

上一篇:lavarel 响应宏
下一篇:Linux内核学习第4天
相关文章