题目:
Problem Description
CA loves to play with sticks.
One day he receives four pieces of sticks, he wants to know these sticks can spell a quadrilateral.
(What is quadrilateral? Click here: https://en.wikipedia.org/wiki/Quadrilateral)
One day he receives four pieces of sticks, he wants to know these sticks can spell a quadrilateral.
(What is quadrilateral? Click here: https://en.wikipedia.org/wiki/Quadrilateral)
Input
First line contains
T
denoting the number of testcases.
T testcases follow. Each testcase contains four integers a,b,c,d in a line, denoting the length of sticks.
1≤T≤1000, 0≤a,b,c,d≤263−1
T testcases follow. Each testcase contains four integers a,b,c,d in a line, denoting the length of sticks.
1≤T≤1000, 0≤a,b,c,d≤263−1
Output
For each testcase, if these sticks can spell a quadrilateral, output "Yes"; otherwise, output "No" (without the quotation marks).
Sample Input
2 1 1 1 1 1 1 9 2
Sample Output
Yes No
题解:
组成四边形的条件就是任意3边之和大于第4边,注意0的情况。
long long数据可能会爆 ,用unsigned long long 会比较好。
代码:
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
int t;
int a[1005];
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
double pro;
pro=0;
for(int i=1;i<=n;i++)
{
double count=0;
for(int j=1;j<=n;j++)
{
if(a[i]>a[j]) count++;
}
pro+=(count/(n-1))/n;
}
printf("%.6f\n",pro);
}
return 0;
}