Codeforces Round #261 (Div. 2)题解

这次CF整体不算太难,所有题目YY一下都能够有思路,也没什么好多说的东西。。。

A题:

A. Pashmak and Garden
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Pashmak has fallen in love with an attractive girl called Parmida since one year ago...

Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones.

Input

The first line contains four space-separated x1, y1, x2, y2 ( - 100 ≤ x1, y1, x2, y2 ≤ 100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct.

Output

If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3, y3, x4, y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them.

Note that x3, y3, x4, y4 must be in the range ( - 1000 ≤ x3, y3, x4, y4 ≤ 1000).

Sample test(s)
input
0 0 0 1
output
1 0 1 1
input
0 0 1 1
output
0 1 1 0
input
0 0 1 2
output
-1


题目给定一对坐标,让求另外两个坐标,使得围成的四边形为平行于坐标轴的正方形,没什么好说的,直接分情况考虑给定点为平行y轴,x轴,对角线的点(PS:平行于对角线的点就是横纵坐标差的绝对值相同的点,好多人因为未考虑绝对值被hack有点小忧伤),具体代码如下:

#include
#include
#include
using namespace std;
int cal(int x)
{
    if(x>0)return x;
    return -x;
}
int main()
{
    int pax1,pax2,pay1,pay2;
    cin>>pax1>>pay1>>pax2>>pay2;
    {
        int t1=pax1-pax2,t2=pay1-pay2;
        if(t1==0)
        {
            if(t2==0)
            {
                printf("%d %d %d %d\n",pax1,pay2,pax1,pay2);
            }
            else
            {
                printf("%d %d %d %d\n",pax1+t2,pay1,pax2+t2,pay2);
            }
        }
        else
        {
            if(t2==0)
            {
                printf("%d %d %d %d\n",pax1,pay1+t1,pax2,pay2+t1);
            }
            else if(cal(t1)==cal(t2))
            {
                printf("%d %d %d %d\n",pax1,pay2,pax2,pay1);
            }
            else
                printf("-1\n");

        }
    }
    return 0;
}


B题:

B. Pashmak and Flowers
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Pashmak decided to give Parmida a pair of flowers from the garden. There are n flowers in the garden and the i-th of them has a beauty number bi. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference is maximal possible!

Your task is to write a program which calculates two things:

  1. The maximum beauty difference of flowers that Pashmak can give to Parmida.
  2. The number of ways that Pashmak can pick the flowers. Two ways are considered different if and only if there is at least one flower that is chosen in the first way and not chosen in the second way.
Input

The first line of the input contains n (2 ≤ n ≤ 2·105). In the next line there are n space-separated integers b1b2, ..., bn (1 ≤ bi ≤ 109).

Output

The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively.

Sample test(s)
input
2
1 2
output
1 1
input
3
1 4 5
output
4 1
input
5
3 1 2 3 1
output
2 4
Note

In the third sample the maximum beauty difference is 2 and there are 4 ways to do this:

  1. choosing the first and the second flowers;
  2. choosing the first and the fifth flowers;
  3. choosing the fourth and the second flowers;
  4. choosing the fourth and the fifth flowers.

题目要求给定一组数列,求最大和最小的差及其构成方案,还是一个水题,就是求出最大最小以及数量,然后输出最大最小差外加最大最小数量相乘的积就OK了,但是WA点真心多,First,如果直接相乘,会爆int,所以方法就是直接全部搞成long long,Second,可能会出现一组所有元素都相等的情况,这种情况解决方案就不是pmax*pmin了,而是(n-1)*n/2,注意这些就可AC。。。

#include
#include
using namespace std;
long long res[200005];
int main()
{
    long long n;
    while(cin>>n)
    {
        long long maxx=0,minn=1000000001,pmi=0,pma=0;
        for(int i=0;i>res[i];
            if(res[i]>maxx)
            {
                maxx=res[i];
                pma=1;
            }
            else if(res[i]==maxx)
            {
                pma++;
            }
            if(res[i]


C题:

C. Pashmak and Buses
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Recently Pashmak has been employed in a transportation company. The company has k buses and has a contract with a school which has n students. The school planned to take the students to d different places for d days (each day in one place). Each day the company provides all the buses for the trip. Pashmak has to arrange the students in the buses. He wants to arrange the students in a way that no two students become close friends. In his ridiculous idea, two students will become close friends if and only if they are in the same buses for all d days.

Please help Pashmak with his weird idea. Assume that each bus has an unlimited capacity.

Input

The first line of input contains three space-separated integers n, k, d (1 ≤ n, d ≤ 1000; 1 ≤ k ≤ 109).

Output

If there is no valid arrangement just print -1. Otherwise print d lines, in each of them print n integers. The j-th integer of the i-th line shows which bus the j-th student has to take on the i-th day. You can assume that the buses are numbered from 1 to k.

Sample test(s)
input
3 2 2
output
1 1 2 
1 2 1 
input
3 2 1
output
-1
Note

Note that two students become close friends only if they share a bus each day. But the bus they share can differ from day to day.


这个题需要一点yy,具体题目就是给你n个人,k辆车,还有d天,要求每个人d天坐车方案至少有有一天不同,这个本身一直想着dp,最后发现是个死胡同,突然就想到计数问题,如果用k进制数记n个d位的数即可满足题目要求,但是当时时间不够,最后么有拍出来,具体实现代码如下(PS:还是不算难的其实):

#include
#include
#include
#include
#include
#include
using namespace std;
int sum[1005][1005];
int main()
{
 //   freopen("in.txt","r",stdin);
    int n,k,d;
    while(cin>>n>>k>>d)
    {
        memset(sum,0,sizeof(sum));
        int flag=0;
        for(int i=1;i=k && j>=0)
            {
                sum[j][i]=0;
                j--;
                if(j>=0)
                    sum[j][i]=sum[j][i-1]+1;
            }
            if(j==-1)
            {
                flag=1;
                break;
            }
            j--;
            while(j>=0)
            {
                sum[j][i]=sum[j][i-1];
                j--;
            }
        }
        if(flag==1)
            cout<<-1<


D题:(未完待续,还么有读题呢。。。)

你可能感兴趣的:(ACM)