HihoCoder-1578 Visiting Peking University(模拟,ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

描述

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天(天数的下标从0开始),每一天都有一个权值,要从里面选出连续的m天,求在这m天中,第一天与这m天中的另一天的权值和的最小值。
又给了k天,这k天不能用,算连续的天数的时候可以跳过k天

直接模拟就好

代码

#include<cstdio>
#include<cstring>
#include<string>
#include<set>
#include<iostream>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define mod 10000007
#define debug() puts("what the fuck!!!")
#define ll longlong
using namespace std;
const int N=100+20;
int a[N],vis[N];
int main()
{
    int n,m,k,x;
    while(~scanf("%d%d",&n,&m))
    {
        mem(vis,0);
        for(int i=0; i<n; i++)
            scanf("%d",&a[i]);
        scanf("%d",&k);
        for(int i=0; i<k; i++)
        {
            scanf("%d",&x);
            vis[x]=1;
        }
        int minn=inf,l,r;
        for(int i=0; i<=n-m; i++)
        {
            if(vis[i]) continue;
            int maxb=inf;
            int t=0;
            for(int j=i+1; j<n; j++)
            {
                if(!vis[j])
                {
                    if(a[j]<maxb)
                    {
                        maxb=a[j];
                        k=j;
                    }
                    t++;
                    if(t==m-1)break;
                }
            }
            if(t!=m-1)break;
            if(a[i]+a[k]<minn)
            {
                minn=a[i]+a[k];
                l=i;
                r=k;
            }
        }
        printf("%d %d\n",l,r);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值