zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 37 A B C

    A. Water The Garden
    time limit per test1 second
    memory limit per test256 megabytes
    inputstandard input
    outputstandard output
    It is winter now, and Max decided it's about time he watered the garden.

    The garden can be represented as n consecutive garden beds, numbered from 1 to n. k beds contain water taps (i-th tap is located in the bed xi), which, if turned on, start delivering water to neighbouring beds. If the tap on the bed xi is turned on, then after one second has passed, the bed xi will be watered; after two seconds have passed, the beds from the segment [xi - 1, xi + 1] will be watered (if they exist); after j seconds have passed (j is an integer number), the beds from the segment [xi - (j - 1), xi + (j - 1)] will be watered (if they exist). Nothing changes during the seconds, so, for example, we can't say that the segment [xi - 2.5, xi + 2.5] will be watered after 2.5 seconds have passed; only the segment [xi - 2, xi + 2] will be watered at that moment.

    The garden from test 1. White colour denotes a garden bed without a tap, red colour — a garden bed with a tap.
    The garden from test 1 after 2 seconds have passed after turning on the tap. White colour denotes an unwatered garden bed, blue colour — a watered bed.
    Max wants to turn on all the water taps at the same moment, and now he wonders, what is the minimum number of seconds that have to pass after he turns on some taps until the whole garden is watered. Help him to find the answer!

    Input
    The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 200).

    Then t test cases follow. The first line of each test case contains two integers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n) — the number of garden beds and water taps, respectively.

    Next line contains k integers xi (1 ≤ xi ≤ n) — the location of i-th water tap. It is guaranteed that for each condition xi - 1 < xi holds.

    It is guaranteed that the sum of n over all test cases doesn't exceed 200.

    Note that in hacks you have to set t = 1.

    Output
    For each test case print one integer — the minimum number of seconds that have to pass after Max turns on some of the water taps, until the whole garden is watered.

    Example
    input
    3
    5 1
    3
    3 3
    1 2 3
    4 1
    1
    output
    3
    1
    4
    Note
    The first example consists of 3 tests:

    There are 5 garden beds, and a water tap in the bed 3. If we turn it on, then after 1 second passes, only bed 3 will be watered; after 2 seconds pass, beds [1, 3] will be watered, and after 3 seconds pass, everything will be watered.
    There are 3 garden beds, and there is a water tap in each one. If we turn all of them on, then everything will be watered after 1 second passes.
    There are 4 garden beds, and only one tap in the bed 1. It will take 4 seconds to water, for example, bed 4.

    题意

    花园的某些位置上有水龙头,水龙头往两边浇水,问最少需要多少秒可以把所有位置都浇上水。

    题解

    水题不解释了。。

    #include<iostream>
    #include<algorithm>
    using namespace std;
    int a[205];
    int main()
    {
    	int t;
    	cin>>t;
    	while(t--)
    	{
    		int n,k;
    		cin>>n>>k;
    		a[0]=1;
    		int L=0;
    		for(int i=1;i<=k;i++)
    		{
    			cin>>a[i];
    			if(i>1)
    				L=max(L,(a[i]-a[i-1])/2);
    		}
    		L=max(L,a[1]-a[0]);
    		L=max(L,n-a[k]);
    		cout<<L+1<<endl;
    	}
    	return 0;
    } 
    

    B. Tea Queue
    time limit per test1 second
    memory limit per test256 megabytes
    inputstandard input
    outputstandard output
    Recently n students from city S moved to city P to attend a programming camp.

    They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.

    i-th student comes to the end of the queue at the beginning of li-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of ri-th second student i still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea.

    For each student determine the second he will use the teapot and get his tea (if he actually gets it).

    Input
    The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 1000).

    Then t test cases follow. The first line of each test case contains one integer n (1 ≤ n ≤ 1000) — the number of students.

    Then n lines follow. Each line contains two integer li, ri (1 ≤ li ≤ ri ≤ 5000) — the second i-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea.

    It is guaranteed that for every condition li - 1 ≤ li holds.

    The sum of n over all test cases doesn't exceed 1000.

    Note that in hacks you have to set t = 1.

    Output
    For each test case print n integers. i-th of them must be equal to the second when i-th student gets his tea, or 0 if he leaves without tea.

    Example
    input
    2
    2
    1 3
    1 4
    3
    1 5
    1 1
    2 3
    output
    1 2
    1 0 2
    Note
    The example contains 2 tests:

    During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second.
    During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea.

    题意

    排队喝茶,给出每个人到达的时间,和最多等待到的时间,问每个人最早能喝到茶的时间。

    题解

    模拟就好。

    #include<iostream>
    #include<algorithm>
    using namespace std;
    int beg[5005],en[5005];
    int main()
    {
    	int t;
    	cin>>t;
    	while(t--)
    	{
    		int n;
    		cin>>n;
    		for(int i=0;i<n;i++)
    			cin>>beg[i]>>en[i];
    		int st=1;
    		for(int i=0;i<n;i++)
    		{
    			if(en[i]>=st)
    			{
    				if(beg[i]>st)
    				{
    					cout<<beg[i]<<' ';
    					st=beg[i];
    				}
    				else
    				{
    					cout<<st<<' ';
    				}
    				st++;
    			}
    			else
    			{
    				cout<<"0 ";
    			}
    		}
    		cout<<endl;
    	}
    	return 0;
    }
    

    C. Swap Adjacent Elements
    time limit per test1 second
    memory limit per test256 megabytes
    inputstandard input
    outputstandard output
    You have an array a consisting of n integers. Each integer from 1 to n appears exactly once in this array.

    For some indices i (1 ≤ i ≤ n - 1) it is possible to swap i-th element with (i + 1)-th, for other indices it is not possible. You may perform any number of swapping operations any order. There is no limit on the number of times you swap i-th element with (i + 1)-th (if the position is not forbidden).

    Can you make this array sorted in ascending order performing some sequence of swapping operations?

    Input
    The first line contains one integer n (2 ≤ n ≤ 200000) — the number of elements in the array.

    The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 200000) — the elements of the array. Each integer from 1 to n appears exactly once.

    The third line contains a string of n - 1 characters, each character is either 0 or 1. If i-th character is 1, then you can swap i-th element with (i + 1)-th any number of times, otherwise it is forbidden to swap i-th element with (i + 1)-th.

    Output
    If it is possible to sort the array in ascending order using any sequence of swaps you are allowed to make, print YES. Otherwise, print NO.

    Examples
    input
    6
    1 2 5 3 4 6
    01110
    output
    YES
    input
    6
    1 2 5 3 4 6
    01010
    output
    NO
    Note
    In the first example you may swap a3 and a4, and then swap a4 and a5.

    题意

    给一个数列,再给出相邻的数字之间能否交换,问能否通过交换(不计次数)使其成为有序序列。

    题解

    如果连续的几个数可以交换,那么对这一段连续可交换的数列进行排序。对所有的连续数进行排序,最后检查一下,是否仍然有乱序,若有则显然无论如何也不能让其有序。

    #include<iostream>
    #include<algorithm>
    using namespace std;
    const int maxn=2e5+5;
    int a[maxn];
    char s[maxn];
    int main()
    {
    	ios::sync_with_stdio(false);
    	int n;
    	cin>>n;
    	for(int i=0;i<n;i++)
    		cin>>a[i];
    	cin>>s;
    	for(int i=0;i<n-1;i++)
    	{
    		if(s[i]=='1')
    		{
    			int j=i;
    			for(;s[j]=='1';j++);
    			sort(a+i,a+j+1);
    			i=j;
    		}
    	}
    	for(int i=0;i<n-1;i++)
    		if(a[i]>a[i+1])
    			return puts("NO"),0;
    	puts("YES");
    	return 0;
    }
    
  • 相关阅读:
    mysql 重置root 账户密码
    Applicationpoolidentity 好有趣哦
    类模板的困扰 LNK2019 (转)
    C++中定义比较函数的三种方法
    Spring的AOP,Struts2的拦截器(Interceptor),以及springMVC的(interceptor)
    MyBatis与Hibernate总结篇
    Java中的回调
    闲来重写一下快速排序
    【lucene】一个简单的招聘网站的建立
    【Lucene】小谈lucene的BooleanQuery查询对象
  • 原文地址:https://www.cnblogs.com/orion7/p/8414728.html
Copyright © 2011-2022 走看看