Description
福大新校區的周圍有若干個養鴨場,當然鴨羣裏面也有另類的。養鴨場的老闆認爲,這些另類的鴨子,要麼可以賣個好價錢,要麼一文不值。
我們定義每隻鴨子的特徵爲一個一維的0-1向量如:
鴨子a1在這三隻鴨子裏的另類度爲:dist (a1,a1)+dist (a1,a2)+dist (a1,a3)。
定義dist運算爲:
dist (a1,a1)= (|1-1|+|0-0|+|0-0|+|1-1|+|0-0|) = 0
dist (a1,a2) = (|1-0|+|0-1|+|0-0|+|1-0|+|0-1|) = 4;
dist (a1,a3) = (|1-0|+|0-0|+|0-1|+|1-0|+|0-1|) = 4;
就得到鴨子a1在這三隻鴨子裏的另類度爲8。
另類的鴨子越多,風險就越大,因此,養鴨場的老闆希望可以確定他的鴨羣裏面到底有多少另類的鴨子。
Input
每組數據第一行爲空格隔開的三個整數n、m和p。n表示有n只鴨子(2 <= n <= 10,000),m表示這羣鴨子有m個特徵值(5 <= m <= 200),p表示另類度的界限,認爲大於等於p的另類度的鴨子就爲另類的鴨子(0 <= p <= 2,000,000)。
接下來n行,每行有m個用空格隔開的0或1數字,表示鴨子的特徵值。
Output
Sample Input
1 3 5 8 1 0 0 1 0 0 1 0 0 1 0 0 1 0 1
Sample Output
Case 1: 1
題解
剛開始沒有想到沒有思路
後來突然想明白了
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
using namespace std;
//struct node
//{
// int a[205];
//}s[10005];
int a[10005][205];
int sum[205];
int main()
{
int t,n,m,p,ans,summ;
scanf("%d",&t);
int tt=1;
while(t--)
{
summ=0;
scanf("%d%d%d",&n,&m,&p);
for(int i=0;i<10005;i++)
{
for(int j=0;j<205;j++)
{
sum[j]=0;
a[i][j]=0;
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
scanf("%d",&a[i][j]);
sum[j]+=a[i][j];
}
}
for(int i=1;i<=n;i++)
{
ans=0;
for(int j=1;j<=m;j++)
{
if(a[i][j]==0)
{
ans+=sum[j];
}
else
{
ans+=n-sum[j];
}
}
if(ans>=p)
summ++;
}
printf("Case %d: %d\n",tt++,summ);
}
}