【链接】 我是链接,点我呀:)
【题意】

在这里输入题意

【题解】

翻转一次最多影响2k+1个地方。
如果n<=k+1
那么放在1的位置就ok.因为能覆盖1..k+1
如果n<=2
k+1
那么就放在1+k的位置就ok.能覆盖1..2k+1
其他情况
考虑temp=n%(2
k+1)的值。
如果temp==0
那么美滋滋。直接操作n/(2k+1)次就ok,
分别在1+k,1+k+2
k+1,1+k+2k+1+2k+1....
刚好占据n个位置。
如果k+1<=temp<=2k
那么我们可以在temp-k的位置操作一次。
这样的话。一开始的位置我们就能先翻转temp个了。然后剩下的再按照2
k+1依次操作(就能刚好铺满n个了)
如果1<=temp<=k
那么我们考虑在1位置操作一次。
这样能翻转1..k+1这k+1个位置。
对于最后的2k+1和temp这两段。
我们把它分解一下。
因为已经翻转了k+1个
所以还剩下rest=2
k+1+temp-(k+1)
会发现rest∈[k+1,2*k]
而这么一段。
可以在n-(rest-k)+1的位置操作一次填掉。
那么剩下的部分就能被2k+1整除了。按顺序放就可以了。
然后这两种temp%(2
k+1)!=0的情况操作次数都是n/(2*k+1) + 1

【代码】

#include <bits/stdc++.h>
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define lson l,mid,rt<<1
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rs(x) scanf("%s",x)
#define rson mid+1,r,rt<<1|1
using namespace std;const double pi = acos(-1);
const int dx[4] = {0,0,1,-1};
const int dy[4] = {1,-1,0,0};const int N = 20;int n,k;int main(){#ifdef LOCAL_DEFINEfreopen("rush_in.txt", "r", stdin);#endifscanf("%d%d",&n,&k);if (k+1>=n){cout<<1<<endl;cout<<1<<endl;return 0;}else if (2*k+1>=n){//n>k+1cout<<1<<endl;cout<<k+1<<endl;return 0;}int temp = n%(2*k+1);int points = n/(2*k+1);if (temp==0){printf("%d\n",points);int x = k+1;rep1(i,1,points){cout<<x<<' ';x = x+k+1+k;}}else {if (temp>=k+1){points++;cout<<points<<endl;int x = temp-k;rep1(i,1,points){cout<<x<<' ';x = x + k+1+k;}}else{//temp<=kpoints++;cout<<points<<endl;cout<<1<<' ';points--;int x = 1;rep1(i,1,points){x = x+k+1+k;cout<<x<<' ';}}}return 0;
}

转载于:https://www.cnblogs.com/AWCXV/p/9597328.html

【Codeforces Round #507 (Div. 2, based on Olympiad of Metropolises) B】Shashlik Cooking相关推荐

  1. 【Codeforces Round #507 (Div. 2, based on Olympiad of Metropolises) A】Palindrome Dance

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] i从1..n/2循环一波. 保证a[i]和a[n-i+1]就好. 如果都是2的话填上min(a,b)*2就好 其他情况跟随非2的. ...

  2. Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises)

    A. Fraction 题目链接:http://codeforces.com/contest/854/problem/A 题目意思:给出一个数n,求两个数a+b=n,且a/b不可约分,如果存在多组满足 ...

  3. 【Codeforces Round #565 (Div. 3) A B C D E F】解题报告

    Codeforces 565 失踪人口回归 cf 565 A 题意 你可以把一个偶数变成 n/2 , 可以把一个3的倍数变成 n2/3, 可以把一个5的倍数变成 n4/5 问你最少通过多少步可以变成1 ...

  4. Codeforces Round #507 (Div. 1) D. You Are Given a Tree 根号分治 + dp

    传送门 题意: 有一颗nnn个节点的树,其中一个简单路径集合被称为kkk合法当且仅当: 树的每个节点至多属于一条路径,且每条路径恰好包含kkk个点. 对于k∈[1,n]k\in [1,n]k∈[1,n ...

  5. 【Codeforces Round #767 (Div. 2)】 C. Meximum Array 题解

    [Codeforces Round #767 (Div. 2) ]C. Meximum Array 题解 1629C: Meximum Array 题解 [Codeforces Round #767 ...

  6. Codeforces Round #740 (Div. 2, based on VK Cup 2021 - Final (Engine))

    Codeforces Round #740 (Div. 2, based on VK Cup 2021 - Final (Engine)) 题号 题目 知识点 A Simply Strange Sor ...

  7. Codeforces Round #740 (Div. 2, based on VK Cup 2021 - Final (Engine)) A-F全题解

    Codeforces Round #740 (Div. 2, based on VK Cup 2021 - Final (Engine)) 文章目录 A. Simply Strange Sort B. ...

  8. C. Tyler and Strings(组合数学,树状数组维护前缀和)(Codeforces Round #775 (Div. 1, based on Moscow Open Olympiad i)

    对我来说比较困难的一题了,尝试着自己写了一下,调不出来遂放弃. Codeforces Round #775 (Div. 1, based on Moscow Open Olympiad in Info ...

  9. Codeforces Round #775 (Div. 2, based on Moscow Open Olympiad in Informatics)简训

    Codeforces Round #775 (Div. 2, based on Moscow Open Olympiad in Informatics)简训 导语 涉及的知识点 题目 A Game B ...

最新文章

  1. 散粉在哪个步骤用_美妆大神的定妆大法竟然这么好用?用完都不想卸妆了
  2. 直接排序python实现
  3. 程序员,别了校园入了江湖
  4. GitLab-CI与GitLab-Runner
  5. 【API进阶之路】因为不会创建云服务器,我被实习生摆了一道
  6. SQLServer分页查询
  7. 该设备或资源(Web代理)未设置为接受端口“7890“上的连接解决方案
  8. 1、Spring Boot 中 SpringApplication初始化(ok)
  9. STM32CubeIDE Audio播放音频 WM8978 + I2S + DMA双缓存模式
  10. 微信自定义菜单java_java微信开发API第四步 微信自定义个性化菜单实现
  11. Perspectives
  12. 非谓语动词 + 情态动词学习笔记
  13. WLAN 无线局域网
  14. receptive field,即感受野
  15. Pytorch的自定义拓展:torch.nn.Module和torch.autograd.Function
  16. 精品实用小软件汇总(附下载地址)
  17. 使用OpenSSH证书认证
  18. Happy Women‘s Day I 巾帼设计力,引领新时代!
  19. 如何让电脑微信双开呢,两行代码解决问题
  20. 转帖:长时间坐着工作腰疼的解决办法

热门文章

  1. 每个程序猿必读的10篇文章
  2. 路强 java 百度云,解决 Tried to download(403): 。。。zopfli-v2.0.2
  3. 队列阻塞_Java并发|阻塞队列ArrayBlockingQueue解析
  4. ffmpeg 硬解码
  5. GBK转unicode码查询表的改进
  6. 【Elasticsearch】需要监控的 10 大 Elasticsearch 指标
  7. 【Elasticsearch】揭秘 Elasticsearch 分片分配
  8. 【es】使用ElasticSearch的44条建议 性能优化
  9. 【Kafka】Kafka幂等性原理及实现剖析
  10. 【Spring】Spring的生态项目