B. Dima and To-do List----暴力
来源:互联网 发布:华为mate9怎么样知乎 编辑:程序博客网 时间:2024/05/18 01:06
You helped Dima to have a great weekend, but it's time to work. Naturally, Dima, as all other men who have girlfriends, does everything wrong.
Inna and Dima are now in one room. Inna tells Dima off for everything he does in her presence. After Inna tells him off for something, she goes to another room, walks there in circles muttering about how useless her sweetheart is. During that time Dima has time to peacefully complete k - 1 tasks. Then Inna returns and tells Dima off for the next task he does in her presence and goes to another room again. It continues until Dima is through with his tasks.
Overall, Dima has n tasks to do, each task has a unique number from 1 to n. Dima loves order, so he does tasks consecutively, starting from some task. For example, if Dima has 6 tasks to do in total, then, if he starts from the 5-th task, the order is like that: first Dima does the 5-th task, then the 6-th one, then the 1-st one, then the 2-nd one, then the 3-rd one, then the 4-th one.
Inna tells Dima off (only lovingly and appropriately!) so often and systematically that he's very well learned the power with which she tells him off for each task. Help Dima choose the first task so that in total he gets told off with as little power as possible.
The first line of the input contains two integers n, k (1 ≤ k ≤ n ≤ 105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 103), where ai is the power Inna tells Dima off with if she is present in the room while he is doing the i-th task.
It is guaranteed that n is divisible by k.
In a single line print the number of the task Dima should start with to get told off with as little power as possible. If there are multiple solutions, print the one with the minimum number of the first task to do.
6 23 2 1 6 5 4
1
10 51 3 5 7 9 9 4 1 8 5
3
Explanation of the first example.
If Dima starts from the first task, Inna tells him off with power 3, then Dima can do one more task (as k = 2), then Inna tells him off for the third task with power 1, then she tells him off for the fifth task with power 5. Thus, Dima gets told off with total power 3 + 1 + 5 = 9. If Dima started from the second task, for example, then Inna would tell him off for tasks 2, 4 and 6 with power 2 + 6 + 4 = 12.
Explanation of the second example.
In the second example k = 5, thus, Dima manages to complete 4 tasks in-between the telling off sessions. Thus, Inna tells Dima off for tasks number 1 and 6 (if he starts from 1 or 6), 2 and 7 (if he starts from 2 or 7) and so on. The optimal answer is to start from task 3 or 8, 3 has a smaller number, so the answer is 3.
题目链接:http://codeforces.com/contest/366/problem/B
题目的意思是找一个满足以1~k-1为起点,k为间隔的最小子序列。
直接暴力枚举起始点。
代码:
#include <cstdio>#include <cstring>#include <iostream>using namespace std;int a[100010];int main(){int n,mix,k,sum;int pos=0;scanf("%d%d",&n,&k);for(int i=0;i<n;i++){scanf("%d",&a[i]);}for(int i=0;i<k;i++){sum=0;for(int j=i;j<n;j+=k){sum+=a[j];}if(sum<mix){mix=sum;pos=i;}}printf("%d\n",pos+1);return 0;}
- B. Dima and To-do List----暴力
- B. Dima and To-do List
- B - Dima and To-do List
- CodeForces 366B - Dima and To-do List
- CodeForces - 366B Dima and To-do List (模拟) 水
- CodeForces - 366B Dima and To-do List
- Codeforces 366B Dima and To-do List 【模拟】
- CodeForces - 366B Dima and To-do List
- CodeForces 366B:Dima and To-do List【水】
- Codeforces Round #214 (diy.2) B. Dima and To-do List
- Codeforces 460B Little Dima and Equation(暴力)
- Codeforces 460B Little Dima and Equation【思维+暴力】
- B. Dima and Sequence
- [to do list][PCB][questions]and[plan]
- B. Dima and Text Messages
- B. Little Dima and Equation
- B. Little Dima and Equation
- B. Little Dima and Equation
- Linux系统中使用 DD 命令测试 USB 和 SSD 硬盘的读写速度
- SQL数据库中数据类型ntext和text的区别
- Jquery中阻止默认冒泡事件
- [Windows service crash分析]一次编码转换导致的堆破坏
- VMware 12和宿主机网络互通
- B. Dima and To-do List----暴力
- Postfix邮件过滤spam和virus函数
- js、jquery 图像载入效果 Image Loading Effect
- dySE:一个 Java 搜索引擎的实现
- JSON开发笔记(三)—— JSON Schema实战(中)
- 关注国情民情,从身边做起
- 达内课程-各种监听器
- 聚集索引与非聚集索引的区别
- centos7 配置 php mysql appche 环境