摘要:
链接:http://poj.org/problem?id=1063题意:把若干个白球和黑球围成一圈,每个球都可以与与它距离为2的球交换位置,判断能否把黑球和白球分开;思路:白球和黑球分开最后的结果为把球排成一排后所有白球或者黑球在奇数位上的个数和在偶数位上的个数之差为2以内(不等于2),若总数为奇数,则不管小球的布局如何,一定能使黑白球各自连续。因为在这种情况下,奇位置上的小球通过交换可以移动到偶位置上。而若总数为偶数则需要满足以上要求了,因为为偶数时它们交换相对奇偶性不变.View Code 1 #include <iostream> 2 #include <cstdio& 阅读全文
摘要:
链接:http://poj.org/problem?id=1050题意:求给定的矩阵的最大子矩阵和;思路:将二维转化为一维求最大连续子串和;母串为从原矩阵中截取连续的几行,求其最大子串和;View Code 1 #include <iostream> 2 #include <cstdio> 3 #include <string> 4 #include <cstring> 5 #include <cmath> 6 using namespace std; 7 8 int N, a[105][105], s[105]; 9 10 int 阅读全文