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;
}
题目挺简单, 观察一下就可以得出规律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;
}
相关文章推荐
- UVa:10790 - How Many Points of Intersection?
- 8 UVA 10790 How Many Points of Intersection?
- UVA - 10790 How Many Points of Intersection?
- uva 10790 How Many Points of Intersection?
- UVa 10790 How Many Points of Intersection?(组合数学)
- UVA 10790 - How Many Points of Intersection(数学)
- UVa 10790 - How Many Points of Intersection?
- UVa 10790 - How Many Points of Intersection?
- UVA - 10790 How Many Points of Intersection?
- UVA 10790 (暑假-数学(3)-A - How Many Points of Intersection?)
- Uva 10790 - How Many Points of Intersection?
- UVa 10790 - How Many Points of Intersection?
- UVA - 10790 How Many Points of Intersection?
- uva-10790-How Many Points of Intersection?
- UVA 10790 How Many Points of Intersection? 简单数学题
- UVA 10790-How Many Points of Intersection?#
- UVa 10790 - How Many Points of Intersection?
- uva 10790 - How Many Points of Intersection?
- UVA-10790 How Many Points of Intersection?
- Uva 10790 - How Many Points of Intersection?