ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 A题

题目1 : Visiting Peking University

时间限制: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 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天,要在连续的m天里 选择第一天 和另外的一天去参观北京大学,  每一天都有排队人数,  选择排队最少,

增加限制条件, p天的 交通管制,  哪里也去不了,  可以呆 k天, k>m  如果 在这k天里 有k-m天的交通管制天  也是可以的



暴力模拟一下:


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <stdlib.h>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <vector>
#define mem(a,b) memset(a,b,sizeof(a))
#define findx(x) lower_bound(b+1,b+1+bn,x)-b
#define FIN      freopen("input.txt","r",stdin)
#define FOUT     freopen("output.txt","w",stdout)
#define S1(n)    scanf("%d",&n)
#define SL1(n)   scanf("%I64d",&n)
#define S2(n,m)  scanf("%d%d",&n,&m)
#define SL2(n,m)  scanf("%I64d%I64d",&n,&m)
#define Pr(n)     printf("%d\n",n)

using namespace std;
typedef long long ll;
const double PI=acos(-1);
const int INF=0x3f3f3f3f;
const double esp=1e-6;
const int maxn=1e6+5;
const int MOD=1e9+7;
const int mod=1e9+7;
int dir[5][2]={0,1,0,-1,1,0,-1,0};

ll inv[maxn*2],fac[maxn];
ll gcd(ll a,ll b){ return b?gcd(b,a%b):a;}
ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll ans=exgcd(b,a%b,x,y);ll temp=x;x=y;y=temp-a/b*y;return ans;}
ll lcm(ll a,ll b){ return b/gcd(a,b)*a;}
ll qpow(ll x,ll n){ll res=1;for(;n;n>>=1){if(n&1)res=(res*x)%MOD;x=(x*x)%MOD;}return res;}
void INV(){inv[1] = 1;for(int i = 2; i < maxn; i++) inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){ x=1; y=0; d=a; }else{ ex_gcd(b,a%b,d,y,x); y-=x*(a/b);}}
void Fac(){fac[0]=1;for(int i=1;i<=maxn;i++)fac[i]=(fac[i-1]*i)%MOD;}
ll inv_exgcd(ll a,ll n){ll d,x,y;ex_gcd(a,n,d,x,y);return d==1?(x+n)%n:-1;}
ll inv1(ll b){return b==1?1:(MOD-MOD/b)*inv1(MOD%b)%MOD;}
ll inv2(ll b){return qpow(b,MOD-2);}
ll cal(ll m,ll n){if(m<n)return 0;return (fac[m]*inv[fac[n]]%MOD)%MOD*inv[fac[m-n]]%MOD;}
ll cals(ll m,ll n){if(m<n)return 0;return (fac[m]*inv1(fac[n])%MOD)%MOD*inv1(fac[m-n])%MOD;}


int a[120];
int main()
{
    int n,m,k;
    int q;
    int vis[1200];
    while(~scanf("%d %d",&n,&m))
    {
        mem(vis,0);
        for(int i=0;i<n;i++)
            S1(a[i]);
        cin>>q;
        int x;
        while(q--)
        {
            S1(x);
            vis[x]=1;
        }

        int minn=INF,st;
        int con=0;
        int sum;
        int k=0;
        int ans,ans2;
        for(int i=0;i<n;i++)
        {
            if(vis[i])
            continue;
            con=a[i];
            k=INF;
            int y=m+i-1;;
            int count=0;
            for(int j=i+1;j<=y;j++)
            {
                if(j>=n)
                    break;
                if(vis[j])
                {
                    y++;
                    continue;
                }
                count++;
                if(a[j]<k)
                {
                    k=a[j];
                    ans2=j;
                }
            }
            if(con+k<minn&&count==m-1)
            {
                minn=con+k;
                st=i;
                ans=ans2;
            }
        }
        printf("%d %d\n",st,ans);
    }
    return 0;
}


123

posted @ 2017-09-24 11:11  Sizaif  阅读(209)  评论(0编辑  收藏  举报