zoukankan      html  css  js  c++  java
  • 2017ICPC北京赛区网络赛 Visiting Peking University(简单思维)

    描述

    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天其他任意一天去北大,是的去的时候人最少。
    每天去北大的人数也给出,保证有答案。
    暴力做就可以
     1 #include <iostream>
     2 #include<cstdio>
     3 #include<algorithm>
     4 using namespace std;
     5 int n,m,q;
     6 int p[105];
     7 bool vis[103];
     8 int ans,ansa,ansb, ans1,ansa1,ansb1;
     9 int main()
    10 {
    11    while(~scanf("%d%d",&n,&m))
    12    {
    13     for(int i=0;i<n;i++) {scanf("%d",&p[i]); vis[i]=1;}
    14     scanf("%d",&q);
    15      for(int i=1;i<=q;i++)
    16      {
    17          int x;
    18          scanf("%d",&x);
    19          vis[x]=0;
    20      }
    21      ans=0x7fffffff;
    22      ansa=-1;
    23      ansb=-1;
    24      for(int i=0;i<=n-m;i++)
    25      {
    26          if (vis[i]==0) continue;
    27          int day=1;
    28          ans1=ans;
    29          ansa1=ansa;
    30          ansb1=ansb;
    31          for(int j=i+1;j<n;j++)
    32          {
    33             if (vis[j]==0) continue;
    34             day++;
    35             if(p[j]+p[i]<ans1)
    36                 { ans1=p[i]+p[j]; ansa1=i; ansb1=j;}
    37             if (day==m)
    38             {
    39                 if (ans1<ans){ans=ans1;ansa=ansa1;ansb=ansb1;}
    40                 break;
    41             }
    42          }
    43 
    44      }
    45      printf("%d %d
    ",ansa,ansb);
    46    }
    47     return 0;
    48 }
  • 相关阅读:
    多线程总结三:控制线程
    ios -- 为导航栏添加播放动画
    IOS -- UITableView里面点击一个cell改变其他cell的设置
    IOS -- UICollectionView里面的cell点击,点击一个cell改变其他cell的状态
    ios -- Masonry 更新约束
    IOS--按钮里面 左边文字右边图片的设置
    IOS--时间 NSDate,NSTimeInterval的一些转换
    IOS--通过宽度算高度
    iOS App中添加半透明新手指引
    IOS--解决tableview里面cell 文本输入框键盘遮盖的问题
  • 原文地址:https://www.cnblogs.com/Annetree/p/7593796.html
Copyright © 2011-2022 走看看