【SPOJ-YELBRICK】The Yellow Brick Road【GCD】
来源:互联网 发布:如何评价李中莹 知乎 编辑:程序博客网 时间:2024/05/21 15:09
题意:
给出n个长方体,要割出相同大小的正方体,并使得正方体的个数尽可能小。所有的长方体必须用上,且不能丢弃材料。
个数尽可能少就是让边长尽可能大。
因为要整除所有的边,那么显然对所有的长方体的长宽高取gcd就好了。
算的时候注意开LL。
#include <cstdio>typedef long long LL;const int maxn = 1005;int n, num[maxn][3];inline int iread() {int f = 1, x = 0; char ch = getchar();for(; ch < '0' || ch > '9'; ch = getchar()) f = ch == '-' ? -1 : 1;for(; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';return f * x;}inline int gcd(int a, int b) {for(; b; b ^= a ^= b ^= a %= b);return a;}int main() {while(1) {n = iread();if(n == 0) break;num[1][0] = iread(); num[1][1] = iread(); num[1][2] = iread();int len = gcd(num[1][0], gcd(num[1][1], num[1][2]));for(int i = 2; i <= n; i++) {num[i][0] = iread(); num[i][1] = iread(); num[i][2] = iread();len = gcd(len, gcd(num[i][0], gcd(num[i][1], num[i][2])));}LL ans = 0;for(int i = 1; i <= n; i++)ans += (LL) num[i][0] / len * num[i][1] / len * num[i][2] / len;printf("%lld\n", ans);}return 0;}
0 0
- 【SPOJ-YELBRICK】The Yellow Brick Road【GCD】
- the Yellow Mountain
- zoj3299 Fall the Brick
- Yellow
- zoj 3299 Fall the Brick
- spoj 3871. GCD Extreme
- SPOJ 3871 GCD Extreme
- spoj GCDEX - GCD Extreme
- SPOJ NUMTRYE (gcd)
- The Brick Stops Here dp 01背包
- The Retro Brick:iPhone一秒变大哥大
- Hoj 1488 The Brick Stops Here
- zoj3299 Fall the Brick map 离散化
- 【ZOJ】3299 Fall the Brick 线段树
- ZOJ3299:Fall the Brick(区间更新)
- ZOJ 3299 Fall the Brick (线段树)
- HDU 2354 Another Brick in the Wall
- HDU-2354-Another Brick in the Wall
- scala安装以及环境变量配置(windows)
- html的meta总结,html标签中meta属性使用介绍
- 缓存—Memcached
- 定时器精度
- Oracle 创建数据库以及数据库备份
- 【SPOJ-YELBRICK】The Yellow Brick Road【GCD】
- Android笔记---四大组件之Service服务详解
- 复杂链表的复制
- 数据流分析(二)
- 请求网络之HttpUrlConnection
- iOS 单例
- Android中View事件分发机制
- Android笔记---四大组件之Content Provider内容提供者详解
- python-pickle泡菜学习笔记