[关闭]
@dxbdly 2020-12-20T07:02:10.000000Z 字数 1875 阅读 208

C2020寒假练习赛1

信息学——模拟赛


T1. WORD PROCESSOR

签到题,依照题意模拟即可。

  1. //The code is from dxbdly
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. inline int read()
  5. {
  6. int x=0;
  7. char c=getchar();
  8. bool f=0;
  9. while (!isdigit(c))
  10. f=f|(c=='-'),c=getchar();
  11. while (isdigit(c))
  12. x=(x<<3)+(x<<1)+(c^48),c=getchar();
  13. return f?-x:x;
  14. }
  15. int n,k,now;
  16. string s;
  17. int main(){
  18. n=read(),k=read();
  19. for (register int i=1;i<=n;++i)
  20. {
  21. cin>>s;
  22. int len=s.size();
  23. if (now+len>k)
  24. now=0,printf("\n");
  25. if (now)
  26. printf(" ");
  27. cout<<s;
  28. now+=len;
  29. }
  30. return 0;
  31. }

T2. PHOTOSHOOT

不难发现如果确定了,其他的就都确定了。

又由于最大只有,考虑枚举,容易得出:

在递推的过程中开一个桶记录当前有没有出现过。

由于要求字典序最小,如果当前序列满足题意,就可以直接输出。

时间复杂度

  1. //The code is from dxbdly
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. inline int read()
  5. {
  6. int x=0;
  7. char c=getchar();
  8. bool f=0;
  9. while (!isdigit(c))
  10. f=f|(c=='-'),c=getchar();
  11. while (isdigit(c))
  12. x=(x<<3)+(x<<1)+(c^48),c=getchar();
  13. return f?-x:x;
  14. }
  15. int n;
  16. int b[1005],a[1005];
  17. bool tong[1005],err;
  18. int main(){
  19. n=read();
  20. for (register int i=1;i<n;++i)
  21. b[i]=read();
  22. for (register int i=1;i<=n;++i)
  23. {
  24. err=0,memset(tong,0,sizeof(tong));
  25. a[1]=i,tong[i]=1;
  26. for (register int j=2;j<=n;++j)
  27. {
  28. a[j]=b[j-1]-a[j-1];
  29. if (a[j]<1||a[j]>n||tong[a[j]])
  30. {
  31. err=1;
  32. break;
  33. }
  34. tong[a[j]]=1;
  35. }
  36. if (!err)
  37. break;
  38. }
  39. for (register int i=1;i<n;++i)
  40. printf("%d ",a[i]);
  41. printf("%d",a[n]);
  42. return 0;
  43. }

T3. RACE

由于必须整数秒,很难处理最少多少秒跑米的问题。

反向思考,考虑跑秒最多多少米。

先不考虑限速。

想要跑得最多肯定要一直加速。

但由于有限速的存在,不能一直加速,需要在中途减速。

最优的情况应该是先一直加速

然后一直减速使其结束时低于限速。

所以我们分两段考虑。

首先累计增速路程。

若当前速度超过限速,则开始累计降速路程。

当两端路程和到达时,则得出答案。

  1. //The code is from dxbdly
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. inline int read()
  5. {
  6. int x=0;
  7. char c=getchar();
  8. bool f=0;
  9. while (!isdigit(c))
  10. f=f|(c=='-'),c=getchar();
  11. while (isdigit(c))
  12. x=(x<<3)+(x<<1)+(c^48),c=getchar();
  13. return f?-x:x;
  14. }
  15. int n,t;
  16. inline int work(int x)
  17. {
  18. int cnt=1,t=0,up=0,down=0;
  19. while (cnt)
  20. {
  21. up+=cnt,t++;
  22. if (up+down>=n)
  23. return t;
  24. if (cnt>=x)
  25. {
  26. down+=cnt,t++;
  27. if (up+down>=n)
  28. return t;
  29. }
  30. cnt++;
  31. }
  32. }
  33. int main(){
  34. n=read(),t=read();
  35. while (t--)
  36. {
  37. int x=read();
  38. printf("%d\n",work(x));
  39. }
  40. return 0;
  41. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注