Description
Input
数据的第一行包含一个正整数T表示数据组数(1 <= T <= 100) 接下来T组数据。
对于每组数据,
第一行包含一个正整数N,代表平面上点的个数 。(1<= N <= 50,)
接下来N行,每行包含2个实数Xi, Yi,代表第i个点的坐标 (0.00 <= Xi,Yi <= 100.00小数点后至多2位)
数据不保证不会出现坐标相同的点。
Output
Sample Input
Sample Output
Hint
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;
const double pi=acos(-1.0);
const double eps=1e-6;
const int maxn=105;
struct node
{
double x,y;
} point [maxn];
double Cross(node a1,node a2,node a3)
{
double aa= (a2.y - a1.y) * (a3.x - a1.x) - (a2.x - a1.x) * (a3.y - a1.y);
return fabs(aa/2.0);
}
int main()
{
int T,n,m,tot=1;
cin>>T;
while(T--)
{
cin>>n;
for(int i=0; i<n; i++)
{
cin>>point[i].x>>point[i].y;
}
double sum=0;
for(int i=0; i<n; i++)
for(int j=i+1; j<n; j++)
for(int k=j+1; k<n; k++)
sum+=Cross(point[i],point[j],point[k]);
printf("Case %d: %.1lf\n",tot++,sum);
}
return 0;
}
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stack>
#include <algorithm>
using namespace std;
const int maxn=100;
const double pi=acos(-1.0);
#define LL __int64
int a[maxn],b[maxn];
bool flag[100001];
int main()
{
int t,n,tt,i,j,tot=1;
cin>>t;
while(t--)
{
memset(b,0,sizeof(b));
cin>>n;
for(i=0; i<n; i++){
cin>>j;
b[j]++;
}
tt=0;
for(i=0; i<maxn; i++){
if(b[i]!=0)
{
a[tt++]=b[i];
}
}
int ss=0;
for(i=0; i<tt; i++){
if(a[i]>1)
{
ss+=n-1;
n=n-2;
}
}
printf("Case %d:\n",tot++);
printf("%d\n\n",ss);
}
return 0;
}
思路二:#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;
const double pi=acos(-1.0);
const double eps=1e-6;
const int maxn=105;
int a[maxn];
bool flag[maxn];
int main()
{
int t,n,m,res,tot=1;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
memset(flag,false,sizeof(flag));
for(int i=0; i<n; i++) scanf("%d",&a[i]);
sort(a,a+n);
m=n+1,res=0;
for(int i=0; i<n-1; i++)
{
if((flag[a[i]]==false)&&a[i]==a[i+1])
{
m-=2;
res+=m;
flag[a[i]]=true;
}
}
printf("Case %d:\n",tot++);
printf("%d\n\n",res);
}
return 0;
}
#个人赛第七场解题总结# (FZU 1888 三角形问题II && FZU 1886 音乐 )
原文:http://blog.csdn.net/u013050857/article/details/44809303