【Codeforces Round #507 (Div. 2, based on Olympiad of Metropolises) B】Shashlik Cooking
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
翻转一次最多影响2k+1个地方。
如果n<=k+1
那么放在1的位置就ok.因为能覆盖1..k+1
如果n<=2k+1
那么就放在1+k的位置就ok.能覆盖1..2k+1
其他情况
考虑temp=n%(2k+1)的值。
如果temp==0
那么美滋滋。直接操作n/(2k+1)次就ok,
分别在1+k,1+k+2k+1,1+k+2k+1+2k+1....
刚好占据n个位置。
如果k+1<=temp<=2k
那么我们可以在temp-k的位置操作一次。
这样的话。一开始的位置我们就能先翻转temp个了。然后剩下的再按照2k+1依次操作(就能刚好铺满n个了)
如果1<=temp<=k
那么我们考虑在1位置操作一次。
这样能翻转1..k+1这k+1个位置。
对于最后的2k+1和temp这两段。
我们把它分解一下。
因为已经翻转了k+1个
所以还剩下rest=2k+1+temp-(k+1)
会发现rest∈[k+1,2*k]
而这么一段。
可以在n-(rest-k)+1的位置操作一次填掉。
那么剩下的部分就能被2k+1整除了。按顺序放就可以了。
然后这两种temp%(2k+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相关推荐
- 【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的. ...
- 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不可约分,如果存在多组满足 ...
- 【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 ...
- 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 ...
- 【Codeforces Round #767 (Div. 2)】 C. Meximum Array 题解
[Codeforces Round #767 (Div. 2) ]C. Meximum Array 题解 1629C: Meximum Array 题解 [Codeforces Round #767 ...
- 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 ...
- 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. ...
- 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 ...
- 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 ...
最新文章
- 散粉在哪个步骤用_美妆大神的定妆大法竟然这么好用?用完都不想卸妆了
- 直接排序python实现
- 程序员,别了校园入了江湖
- GitLab-CI与GitLab-Runner
- 【API进阶之路】因为不会创建云服务器,我被实习生摆了一道
- SQLServer分页查询
- 该设备或资源(Web代理)未设置为接受端口“7890“上的连接解决方案
- 1、Spring Boot 中 SpringApplication初始化(ok)
- STM32CubeIDE Audio播放音频 WM8978 + I2S + DMA双缓存模式
- 微信自定义菜单java_java微信开发API第四步 微信自定义个性化菜单实现
- Perspectives
- 非谓语动词 + 情态动词学习笔记
- WLAN 无线局域网
- receptive field,即感受野
- Pytorch的自定义拓展:torch.nn.Module和torch.autograd.Function
- 精品实用小软件汇总(附下载地址)
- 使用OpenSSH证书认证
- Happy Women‘s Day I 巾帼设计力,引领新时代!
- 如何让电脑微信双开呢,两行代码解决问题
- 转帖:长时间坐着工作腰疼的解决办法
热门文章
- 每个程序猿必读的10篇文章
- 路强 java 百度云,解决 Tried to download(403): 。。。zopfli-v2.0.2
- 队列阻塞_Java并发|阻塞队列ArrayBlockingQueue解析
- ffmpeg 硬解码
- GBK转unicode码查询表的改进
- 【Elasticsearch】需要监控的 10 大 Elasticsearch 指标
- 【Elasticsearch】揭秘 Elasticsearch 分片分配
- 【es】使用ElasticSearch的44条建议 性能优化
- 【Kafka】Kafka幂等性原理及实现剖析
- 【Spring】Spring的生态项目