Nowcoder 牛可乐发红包脱单OI赛$

好不容易打一场比赛写完2题信心满满能过结果快读写错炸成0分。。心态崩了。。

A

给一个序列长度n,求把最少数变成1使得任意长度大于等于k的子串gcd=1;

傻逼题。。答案是n/k

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <algorithm>
 4 #include <cstring>
 5 #include <cmath>
 6 #include <queue>
 7 #include <vector>
 8 #include <map>
 9 #define ll long long
10 #define out(a) printf("%d",a)
11 #define ln printf("\n")
12 const int N=1e5+50;
13 const int MOD=1e9+7;
14 using namespace std;
15 int n,k;
16 int read()
17 {
18     int s=0,t=1; char c=getchar();
19     while (c<'0'||c>'9'){if (c=='-') t=-1; c=getchar();}
20     while (c>='0'&&c<='9'){s=s*10+c-'0'; c=getchar();}
21     return s*t;
22 }
23 ll readl()
24 {
25     ll s=0,t=1; char c=getchar();
26     while (c<'0'||c>'9'){if (c=='-') t=-1; c=getchar();}
27     while (c>='0'&&c<='9'){s=s*10+c-'0'; c=getchar();}
28     return s*t;
29 }
30 int main()
31 {
32     cin>>n>>k;
33     cout<<n/k;
34     return 0;
35 }
View Code

B

两个操作,a把序列最后那个数移到最前面,b把序列第三个数移到最前面.

显然操作是循环的,%一下然后模拟就好了...

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <algorithm>
 4 #include <cstring>
 5 #include <cmath>
 6 #include <queue>
 7 #include <vector>
 8 #include <map>
 9 #define ll long long
10 #define out(a) printf("%d ",a)
11 #define ln printf("\n")
12 const int N=1e5+50;
13 const int MOD=1e9+7;
14 using namespace std;
15 int n,m;
16 int a[N],b[N],c[N];
17 int num,now,tot=0,l;
18 char s[N];
19 int read()
20 {
21     int s=0,t=1; char c=getchar();
22     while (c<'0'||c>'9'){if (c=='-') t=-1; c=getchar();}
23     while (c>='0'&&c<='9'){s=s*10+c-'0'; c=getchar();}
24     return s*t;
25 }
26 ll readl()
27 {
28     ll s=0,t=1; char c=getchar();
29     while (c<'0'||c>'9'){if (c=='-') t=-1; c=getchar();}
30     while (c>='0'&&c<='9'){s=s*10+c-'0'; c=getchar();}
31     return s*t;
32 }
33 int find(int len)
34 {
35     int x=0;
36     for (int i=0;i<len-1;i++)
37       x=x*10+s[i]-'0';
38     return x;
39 }
40 int main()
41 {
42     n=read(); m=read();
43     for (int i=1;i<=n;i++)
44       a[i]=read();
45     for (int i=1;i<=m;i++){
46       scanf("%s",s); l=strlen(s);
47       if (s[l-1]=='a') now=n; else now=3;
48         num=find(l)%now; tot=0;
49         for (int j=now-num+1;j<=now;j++)
50           b[++tot]=a[j];
51         for (int j=1;j<=now-num;j++)
52           c[j+num]=a[j];
53         for (int j=1;j<=num;j++)
54           a[j]=b[j];
55         for (int j=num+1;j<=now;j++)
56           a[j]=c[j];
57     }
58     for (int i=1;i<=n;i++)
59       out(a[i]);
60     return 0;
61 }
View Code

 

快读问题就是c没有用getchar()赋初值。。。还好在noip前发现我一直这样写却没发现的错误

本来妥妥200分炸成0分,noip比赛时还是老老实实scanf吧QAQ。。

posted @ 2018-11-02 14:18  Kaleidoscope233  阅读(167)  评论(0编辑  收藏  举报