好贷网好贷款

砝码 碎片问题

发布时间:2016-12-3 2:04:32 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"砝码 碎片问题",主要涉及到砝码 碎片问题方面的内容,对于砝码 碎片问题感兴趣的同学可以参考一下。

#include "stdafx.h" #include <windows.h> int getWeight( int i, int j, int k, int s, int weight) { int x1, x2, x3, x4; for ( x1 = -1; x1 <= 1; x1++ ) for ( x2 = -1; x2 <= 1; x2++ ) for ( x3 = -1; x3 <= 1; x3++ ) for ( x4 = -1; x4 <= 1; x4++ ) if ( x1* i + x2 * j + x3 * k + x4 * s == weight ) { return 1; } return 0; } int Justify( int i, int j, int k, int s ) { int weight; for ( weight = 1; weight <= 40; weight++ ) { if ( !getWeight( i, j, k, s, weight) ) { return 0; } } } void pieces() { int i, j, k, s; for ( i = 0; i <= 40; i++) for ( j = i + 1; j <= 40; j++ ) for( k = j + 1; k <= 40; k++ ) for( s= k + 1; s <= 40; s++ ) if ( i + j + k + s == 40 ) { if ( Justify( i, j, k, s )) { printf(" The weight is broken up 4 pieces: \n"); printf(" %d, %d, %d, %d \n", i, j, k, s ); } } } int main() { pieces(); return 0; }

上一篇:S3C2440上LCD驱动(FrameBuffer)开发(二)
下一篇:toj2892Task 拓扑排序——模板

相关文章

相关评论