您的位置:首页 > 其它

UVa 10790 - How Many Points of Intersection?

2014-04-18 21:23 281 查看
传送门UVa 10790 - How Many Points of Intersection?

题目挺简单, 观察一下就可以得出规律num = n * (n - 1) * m * (m - 1) / 4;

题目要求用long long输出... 于是我就声明了一个变量

long long sum

然后用
int m, n;
接收.
可是这样一来就错了...

后来求助了失踪同学, 了解到如果用int类型的m, n, 在计算[b]n * (n - 1) * m * (m - 1) / 4就会溢出了.[/b]

涨姿势了..



#include <cstdio>
#include <cmath>

using namespace std;

int main()
{
//freopen("input.txt", "r", stdin);
long long m, n;
long long sum;
int count = 1;
int i, j;
while (scanf("%lld%lld", &m, &n))
{
sum = 0;
if (m == 0 && n == 0)
break;
sum = n * (n - 1) * m * (m - 1) / 4;
printf("Case %d: %lld\n", count++, sum);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ACM UVa 10790