描述

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(简单思维)的更多相关文章

  1. 2017ICPC北京赛区网络赛 Minimum(数学+线段树)

    描述 You are given a list of integers a0, a1, …, a2^k-1. You need to support two types of queries: 1. ...

  2. HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)

    HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...

  3. HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛)

    HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛) Panda Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: ...

  4. hdu 4044 2011北京赛区网络赛E 树形dp ****

    专题训练 #include<stdio.h> #include<iostream> #include<string.h> #include<algorithm ...

  5. hdu 4050 2011北京赛区网络赛K 概率dp ***

    题目:给出1-n连续的方格,从0开始,每一个格子有4个状态,左右脚交替,向右跳,而且每一步的步长必须在给定的区间之内.当跳出n个格子或者没有格子可以跳的时候就结束了,求出游戏的期望步数 0:表示不能到 ...

  6. hdu 4049 2011北京赛区网络赛J 状压dp ***

    cl少用在for循环里 #include<cstdio> #include<iostream> #include<algorithm> #include<cs ...

  7. hdu 4045 2011北京赛区网络赛F 组合数+斯特林数 ***

    插板法基础知识 斯特林数见百科 #include<iostream> #include<cmath> #include<cstdio> #include<cs ...

  8. hdu 4043 2011北京赛区网络赛D 概率+大数 **

    推出公式为:P = A(2n,n)/(2^(2n)*n!) 但是不会大数,学完java再补

  9. hdu 4041 2011北京赛区网络赛B 搜索 ***

    直接在字符串上搜索,注意逗号的处理 #include<cstdio> #include<iostream> #include<algorithm> #include ...

随机推荐

  1. HDU-2767-tarjan/Kosaraju求scc

    http://acm.hdu.edu.cn/showproblem.php?pid=2767 问最少添加几条边使得图为强连通. tarjan跑一下,然后对强连通分量缩点,找下此时出度为零和入度为零的点 ...

  2. 元类应用ORM实现

    首先看下一个简单的例子 # 需求 import numbers class Field: pass class IntField(Field): # 数据描述符 def __init__(self, ...

  3. C# 3.0 / C# 3.5 扩展方法

    概述 扩展方法是一种特殊的静态方法,可以像扩展类型上的实例方法一样进行调用,能向现有类型“添加”方法,而无须创建新的派生类型.重新编译或以其他方式修改原始类型. 扩展方法的定义实现: public s ...

  4. 《高性能SQL调优精要与案例解析》一书谈SQL调优(SQL TUNING或SQL优化)学习

    <高性能SQL调优精要与案例解析>一书上市发售以来,很多热心读者就该书内容及一些具体问题提出了疑问,因读者众多外加本人日常工作的繁忙 ,在这里就SQL调优学习进行讨论并对热点问题统一作答. ...

  5. java 类变量初始化顺序

    假定有一个类定义如下: package com.zhang; public final class Girl { // static代码块1 private static String sex = & ...

  6. Java并发编程(五)JVM指令重排

    我是不是学了一门假的java...... 引言:在Java中看似顺序的代码在JVM中,可能会出现编译器或者CPU对这些操作指令进行了重新排序:在特定情况下,指令重排将会给我们的程序带来不确定的结果.. ...

  7. SpringBoot添加webapp目录

    一.文章简述 使用IDEA工具创建的SpringBoot项目本身是没有webapp目录的.如果我们想要添加webapp目录的话,可以手动添加. 二.操作步骤 1)点击IDEA右上角的Project S ...

  8. MakeFile中export的使用

    在shell中,可以使用export修改当前进程的环境变量. 例如:export PATH=.:$PATH 将当前路径加入可执行文件查找路径(PATH)中,这样你就不要敲“./excutable” 来 ...

  9. linux系统管理 基本指令

    命令提示符 [root@ssgao1987 ~]# 'root' 当前登陆用户 'ssgao1987' 主机名 '~' 当前所在目录(home目录) '#' 超级用户的提示符 '$' 普通用户的命令提 ...

  10. linux操作系统及命令Part 1

    1.关于linux系统的安装与流程     (1)下载Vmware workstation 与 linux系统(centos版本.redhat版本.Ubuntu版本...)镜像. (2)详细安装见有道 ...