[ZJ]a858: 數三角形
題目:
http://zerojudge.tw/ShowProblem?problemid=a858
============================================================
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
while(scanf("%d", &n)!=EOF)
{
int ans = n*(n-1)*(n-2)/2/3;
int temp = 0;
for(int i = 0; i < n; i++)
{
int r = 0, b = 0;
for(int j = 0; j < n; j++)
{
int p;
scanf("%d", &p);
if( p == 1 ) r++;
if( p == 2 ) b++;
}
temp += r*b;
}
ans -= temp/2;
printf("%d\n", ans);
}
return 0;
}
http://zerojudge.tw/ShowProblem?problemid=a858
============================================================
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
while(scanf("%d", &n)!=EOF)
{
int ans = n*(n-1)*(n-2)/2/3;
int temp = 0;
for(int i = 0; i < n; i++)
{
int r = 0, b = 0;
for(int j = 0; j < n; j++)
{
int p;
scanf("%d", &p);
if( p == 1 ) r++;
if( p == 2 ) b++;
}
temp += r*b;
}
ans -= temp/2;
printf("%d\n", ans);
}
return 0;
}
留言
張貼留言