2017ICPC北京赛区网络赛 Visiting Peking University(简单思维)
描述
Ming is going to travel for n days and the date of these days can be represented by n integers: 0, 1, 2, …, n-1. He plans to spend m consecutive days(2 ≤ m ≤ n)in Beijing. During these m days, he intends to use the first day and another day to visit Peking university. Before he made his plan, Ming investigated on the number of tourists who would be waiting in line to enter Peking university during his n-day trip, and the results could be represented by an integer sequence p[i] (0 ≤ i ≤ n-1, p[i] represents the number of waiting tourists on day i). To save time, he hopes to choose two certain dates a and b to visit PKU(0 ≤ a < b ≤ n-1), which makes p[a] + p[b] as small as possible.
Unfortunately, Ming comes to know that traffic control will be taking place in Beijing on some days during his n-day trip, and he won’t be able to visit any place in Beijing, including PKU, on a traffic control day. Ming loves Beijing and he wants to make sure that m days can be used to visit interesting places in Beijing. So Ming made a decision: spending k (m ≤ k ≤ n) consecutive days in Beijing is also acceptable if there are k - m traffic control days among those k days. Under this complicated situation, he doesn’t know how to make the best schedule. Please write a program to help Ming determine the best dates of the two days to visit Peking University. Data guarantees a unique solution.
输入
There are no more than 20 test cases.
For each test case:
The first line contains two integers, above mentioned n and m (2 ≤ n ≤ 100, 2 ≤ m ≤ n).
The second line contains n integers, above mentioned p[0] , p[1] , … p[n-1]. (0 ≤ p[i] ≤ 1000, i = 0 ... n-1)
The third line is an integer q (0 ≤ q ≤ n), representing the total number of traffic control days during the n-day trip, followed by q integers representing the dates of these days.
输出
One line, including two integers a and b, representing the best dates for visiting PKU.
样例输入
7 3
6 9 10 1 0 8 35
3 5 6 2
4 2
10 11 1 2
1 2
样例输出
0 3
1 3
告诉你去旅游共n天,在北京待k天(连续),其中恰好k-m天不能出行;
要求这k天里第一天和K天其他任意一天去北大,是的去的时候人最少。
每天去北大的人数也给出,保证有答案。
暴力做就可以
#include <iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,q;
int p[];
bool vis[];
int ans,ansa,ansb, ans1,ansa1,ansb1;
int main()
{
while(~scanf("%d%d",&n,&m))
{
for(int i=;i<n;i++) {scanf("%d",&p[i]); vis[i]=;}
scanf("%d",&q);
for(int i=;i<=q;i++)
{
int x;
scanf("%d",&x);
vis[x]=;
}
ans=0x7fffffff;
ansa=-;
ansb=-;
for(int i=;i<=n-m;i++)
{
if (vis[i]==) continue;
int day=;
ans1=ans;
ansa1=ansa;
ansb1=ansb;
for(int j=i+;j<n;j++)
{
if (vis[j]==) continue;
day++;
if(p[j]+p[i]<ans1)
{ ans1=p[i]+p[j]; ansa1=i; ansb1=j;}
if (day==m)
{
if (ans1<ans){ans=ans1;ansa=ansa1;ansb=ansb1;}
break;
}
} }
printf("%d %d\n",ansa,ansb);
}
return ;
}
2017ICPC北京赛区网络赛 Visiting Peking University(简单思维)的更多相关文章
- 2017ICPC北京赛区网络赛 Minimum(数学+线段树)
描述 You are given a list of integers a0, a1, …, a2^k-1. You need to support two types of queries: 1. ...
- HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)
HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...
- HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛)
HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛) Panda Time Limit: 10000/4000 MS (Java/Others) Memory Limit: ...
- hdu 4044 2011北京赛区网络赛E 树形dp ****
专题训练 #include<stdio.h> #include<iostream> #include<string.h> #include<algorithm ...
- hdu 4050 2011北京赛区网络赛K 概率dp ***
题目:给出1-n连续的方格,从0开始,每一个格子有4个状态,左右脚交替,向右跳,而且每一步的步长必须在给定的区间之内.当跳出n个格子或者没有格子可以跳的时候就结束了,求出游戏的期望步数 0:表示不能到 ...
- hdu 4049 2011北京赛区网络赛J 状压dp ***
cl少用在for循环里 #include<cstdio> #include<iostream> #include<algorithm> #include<cs ...
- hdu 4045 2011北京赛区网络赛F 组合数+斯特林数 ***
插板法基础知识 斯特林数见百科 #include<iostream> #include<cmath> #include<cstdio> #include<cs ...
- hdu 4043 2011北京赛区网络赛D 概率+大数 **
推出公式为:P = A(2n,n)/(2^(2n)*n!) 但是不会大数,学完java再补
- hdu 4041 2011北京赛区网络赛B 搜索 ***
直接在字符串上搜索,注意逗号的处理 #include<cstdio> #include<iostream> #include<algorithm> #include ...
随机推荐
- 内存池、进程池、线程池介绍及线程池C++实现
本文转载于:https://blog.csdn.net/ywcpig/article/details/52557080 内存池 平常我们使用new.malloc在堆区申请一块内存,但由于每次申请的内存 ...
- json 常用的序列化 反序列化对象 代码
序列化对象: ---------------------------------------------------------- Person p = new Person() { Name = & ...
- centos命令行系列之centos查看磁盘空间大小
df -h 扩展: 1.查看当前文件夹所有文件大小 du -sh 2.查看指定文件下所有文件大小 du -h /data/ 3.查看指定文件大小 du -h install.log 4.查指定文件夹大 ...
- 【数据库】SQL语句
SQL 分为两个部分:数据操作语言(DML)和 数据定义语言(DDL).增删改查(CRUD)构成了 SQL 的 DML 部分. SELECT - 从数据库表中获取数据 SELECT 列名 FROM 表 ...
- 部署项目到linux中报Spring MVC报异常:org.springframework.web.util.NestedServletException: Request processing failed
@RequestMapping(value = "/security/login", method = RequestMethod.POST) public ModelAndVie ...
- zookeeper 的心跳
假定:主机 A, B 通过 tcp 连接发送数据,如果拔掉 A 主机的网线,B 是无法感知到的.但是如果 A 定时给 B 发送心跳,则能根据心跳的回复来判断连接的状态. 以 zookeeper 为例: ...
- EvalAI使用——类似kaggle的开源平台,不过没有kernel fork功能,比较蛋疼
官方的代码 https://github.com/Cloud-CV/EvalAI 我一直没法成功import yaml配置举办比赛(create a challenge on EvalAI 使用htt ...
- Qt Widgets——菜单和菜单栏
主窗口MainWindow需要菜单栏QMenuBar及菜单QMenu来组成自身,一般应用程序的所有功能都能在菜单中找到.接下来就来说说它们. QMenu 它添加了很多动作QAction,并用自身组成了 ...
- 把旧系统迁移到.Net Core 2.0 日记(1) - Startup.cs 解析
因为自己到开发电脑转到Mac Air,之前的Webform/MVC应用在Mac 跑不起来,而且.Net Core 2.0 已经比较稳定了. 1. 为什么会有跨平台的.Net Core 近年来,我们已 ...
- kiss word memory post poly peri out ~p 4
1● post p əust 在后面,邮件 2● peri 多 3● poly 周围,靠近