zoukankan      html  css  js  c++  java
  • ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 A题 Visiting Peking University

    题目1 : Visiting Peking University

    时间限制:1000ms

    单点时限:1000ms

    内存限制:256MB

    描述

    Ming is going to travel for n days and the date of these dayscan be represented by n integers: 0, 1, 2, …, n-1. He plans to spend mconsecutive days2 ≤ m ≤ ninBeijing. During these m days, he intends to use the first day and another dayto visit Peking university. Before he made his plan, Ming investigated on thenumber of tourists who would be waiting in line to enter Peking universityduring his n-day trip, and the results could be represented by an integersequence p[i] (0 ≤ i ≤ n-1, p[i] represents the number of waiting tourists onday i). To save time, he hopes to choose two certain dates a and b to visitPKU(0 ≤ a < b ≤ n-1), which makes p[a] + p[b] as small as possible.

    Unfortunately, Ming comes to know that traffic control will betaking place in Beijing on some days during his n-day trip, and he won’t beable 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 visitinteresting 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 trafficcontrol days among those k days. Under this complicated situation, he doesn’tknow how to make the best schedule. Please write a program to help Mingdetermine the best dates of the two days to visit Peking University.  Dataguarantees 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 thetotal number of traffic control days during the n-day trip, followed by q integersrepresenting the dates of these days.

    输出

    One line, including two integers a and b, representing the bestdates 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 第二行有n个数,分别代表第0,1,2....n-1天在北京大学等待的人数
    第三行输入一个k个数,接下来又有k个数表示交通限制的日期是多少
    现在要从没被限制交通的日期里面选择连续的m天去到北大旅行,在m天里面选择两天(这两天的第一天必须是连续m天中的第一天,两天中的等待人数之和又必须是最小)
    最后输出连续的m天中选择的两天的日期是多少*/
    #include <iostream>
     using namespace std;
     struct aa
     {
         int which_day;
         int wait_people;
     }a[101];
     int main()
     {
         int all_wait_people[101];
         int n,m,limit_days;
         while(cin>>n>>m)
         {
             for(int i=0;i<n;++i)
                 cin>>all_wait_people[i];
                cin>>limit_days;
                int day;
             for(int i=0;i<limit_days;++i)
             {
                 cin>>day;
                 all_wait_people[day]=-1;
             }
             int j=0;
             for(int i=0;i<n;++i)
             {
                 if(all_wait_people[i]!=-1)
                 {
                    a[j].which_day=i;
                    a[j++].wait_people=all_wait_people[i];
                 }
             }
             int a0,a1,min=1000;
             for(int i=0;i<=j-m;i++)//不确定i的上界可以把样例中的第一组数据带入验证
             {
                 for(int k=i+1;k<m+i;k++)
                    if(a[i].wait_people+a[k].wait_people<min)
                 {
                     min=a[i].wait_people+a[k].wait_people;
                     a0=a[i].which_day;
                     a1=a[k].which_day;
                 }
             }
             cout<<a0<<' '<<a1<<endl;
         }
         return 0;
     }
    附上队友的:
    #include <iostream>
    #include <cstdio>
    using namespace std;
    #define MAX 1005
    struct Node
    {
        int data;
        int num;
    };
    int main()
    {
        int n,m;
        Node p[MAX],P[MAX];
        while(scanf("%d%d",&n,&m)!=EOF)
        {
            int i;
            for(i=0;i<n;i++)
            {
                scanf("%d",&p[i].data);
                p[i].num = i;
            }
            int q,k;
            scanf("%d",&q);
            for(i=0;i<q;i++)
            {
                scanf("%d",&k);
                p[k].data = -1;
            }
            int j = 0,min = MAX;
            for(i=0;i<n;i++)
                if(p[i].data!=-1)
                {
                    P[j].data = p[i].data;
                    P[j].num = p[i].num;
                    j++;
                }
            int start,end;
            for(i=0;i<=j-m;i++)
            {
                for(k = i+1;k<i+m;k++)
                {
                    if(P[i].data+P[k].data<min)
                    {
                        min = P[i].data+P[k].data;
                        start = P[i].num;
                        end = P[k].num;
                    }
                }
            }
            printf("%d %d
    ",start,end);
        }
        return 0;
    }
    



  • 相关阅读:
    motan rpc
    etcd:从应用场景到实现原理的全方位解读 转自infoq
    微信扫码登录实现原理
    商家历史数据查询及下载
    zookeeper No route to host
    hadoop 一些命令
    spring cloud 转
    Lombok 安装、入门
    Prometheus
    kvm虚拟机静态和动态迁移
  • 原文地址:https://www.cnblogs.com/sxy201658506207/p/7586251.html
Copyright © 2011-2022 走看看