B. Pashmak and Flowers
题意:有许多花,每朵花有一个value,选出value相差最大的两朵花,输出value的差和有多少种选法。
思路:排序,差值就是最后一个的value减去第一个的value。然后选法种数根据乘法原理可得,注意爆int和value全部一样的情况。比赛的时候我逗比了,n*(n-1)/2写成了n/2*(n-1)。。还lock了。。
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <memory.h>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <ctype.h>
#define INF 10000000
#define ll long long
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define MAXN 100010
using namespace std;
int main(){
int x1,y1,x2,y2;
while(cin>>x1>>y1>>x2>>y2){
if(x1==x2){
int t=abs(y1-y2);
cout<<x1+t<<" "<<y1<<" "<<x2+t<<" "<<y2<<endl;
}else if(y1==y2){
int t=abs(x1-x2);
cout<<x1<<" "<<y1+t<<" "<<x2<<" "<<y2+t<<endl;
}else{
int t1=abs(x1-x2);
int t2=abs(y1-y2);
if(t1!=t2){
cout<<"-1"<<endl;
}else{
int t;
if(x1>x2){
t=x2;x2=x1;x1=t;
t=y2;y2=y1;y1=t;
}
cout<<x1<<" "<<y2<<" "<<x2<<" "<<y1<<endl;
}
}
}
return 0;
}
此博客讨论了从一组花朵中找出价值差最大的两朵并计算差值及选择方式的数量,通过排序和数学原理解决实际问题。
1657

被折叠的 条评论
为什么被折叠?



