这次CF整体不算太难,所有题目YY一下都能够有思路,也没什么好多说的东西。。。
A题:
题目给定一对坐标,让求另外两个坐标,使得围成的四边形为平行于坐标轴的正方形,没什么好说的,直接分情况考虑给定点为平行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题:
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:
- The maximum beauty difference of flowers that Pashmak can give to Parmida.
- 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.
Output
The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively.
Note
In the third sample the maximum beauty difference is 2 and there are 4 ways to do this:
- choosing the first and the second flowers;
- choosing the first and the fifth flowers;
- choosing the fourth and the second flowers;
- 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题:
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.
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.
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题:(未完待续,还么有读题呢。。。)