ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 A. Visiting Peking University(模拟水题)

来源:互联网 发布:寻龙诀 知乎 编辑:程序博客网 时间:2024/06/05 05:55

时间限制:1000ms
单点时限:1000ms
内存限制:256MB

描述

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 36 9 10 1 0 8 353 5 6 24 210 11 1 21 2
样例输出
0 31 3

题解:

题目意思比较难懂,懂了就很水,题目意思就是给n天,和一个值m,然后是n天的游客数,然后是k,输入k个禁止的日期,要求取一段连续的长度为m(不包括禁止的天)的日期,取第一天和期中的一天,使得值的和最小

直接暴力枚举就行了

代码:

#include<iostream>#include<cstring>#include<stdio.h>#include<math.h>#include<string>#include<stdio.h>#include<queue>#include<stack>#include<map>#include<vector>#include<deque>#include<algorithm>#define ll long long#define INF 10086111#define M (t[k].l+t[k].r)/2#define lson k*2#define rson k*2+1using namespace std;int a[1005];int vis[1005];int main(){    int i,j,k,n,m,x,d,maxx,minn,ans,d1,d2,t,s;    while(scanf("%d%d",&n,&m)!=EOF)    {        for(i=0;i<n;i++)        {            vis[i]=0;            scanf("%d",&a[i]);        }        scanf("%d",&x);        for(i=0;i<x;i++)        {            scanf("%d",&d);            vis[d]=1;        }        minn=INF;        for(i=0;i<n-m+1;i++)        {            if(vis[i])                continue;            if(a[i]>=minn)                continue;            ans=1;            t=INF;            for(j=i+1;j<n;j++)            {                if(vis[j])                    continue;                if(t>a[j])                {                    t=a[j];                    s=j;                }                ans++;                if(ans==m)                {                    if(minn>a[i]+t)                    {                        minn=a[i]+t;                        d1=i;                        d2=s;                    }                    break;                }            }        }        printf("%d %d\n",d1,d2);    }    return 0;}





阅读全文
0 0