2974
来源:互联网 发布:c语言函数大全pdf下载 编辑:程序博客网 时间:2024/05/16 16:18
#include <cstdio>#include <string>#include <cmath>using namespace std;int n, m, matrix[300][301];inline int date2int(const char *date){if(0 == strcmp("MON", date)){return 1;}else if(0 == strcmp("TUE", date)){return 2;}else if(0 == strcmp("WED", date)){return 3;}else if(0 == strcmp("THU", date)){return 4;}else if(0 == strcmp("FRI", date)){return 5;}else if(0 == strcmp("SAT", date)){return 6;}else{return 7;}}bool input(){scanf("%d%d", &n, &m);if(0 == n || 0 == m){return false;}memset(matrix, 0, sizeof(matrix));int ks, type;char start[4], end[4];for(int i = 0; i < m; ++i){scanf("%d%s%s", &ks, start, end);matrix[i][n] = ((date2int(end) - date2int(start) + 1) % 7 + 7) % 7;for(int j = 0; j < ks; ++j){scanf("%d", &type);++matrix[i][type - 1];}for(int j = 0; j < n; ++j){if(matrix[i][j] >= 7){matrix[i][j] %= 7;}}}return true;}int gcd(int a, int b){int t;while(b != 0){t = b;b = a % b;a = t;}return a;}bool modify(){for(int i = n - 1; i >= 0; --i){for(int j = i + 1; j < n; ++j){matrix[i][n] = ((matrix[i][n] - matrix[i][j] * matrix[j][n]) % 7 + 7) % 7;matrix[i][j] = 0;}for(int j = 3; j <= 9; ++j){if((j * matrix[i][i]) % 7 == matrix[i][n]){matrix[i][n] = j;break;}}matrix[i][i] = 1;}return true;}int gauss(){int row = 0, col = 0;while(row < m && col < n){int sid = row;for(int i = row + 1; i < m; ++i){if(abs(matrix[i][col]) > abs(matrix[sid][col])){sid = i;}}if(0 == matrix[sid][col]){++col;continue;}if(sid != row){for(int i = col; i <= n; ++i){swap(matrix[row][i], matrix[sid][i]);}}for(int i = row + 1; i < m; ++i){if(0 == matrix[i][col]){continue;}const int GCD = gcd(abs(matrix[row][col]), abs(matrix[i][col]));const int t1 = abs(matrix[i][col]) / GCD;const int t2 = abs(matrix[row][col]) / GCD;for(int j = col; j <= n; ++j){matrix[i][j] = ((matrix[i][j] * t2 - matrix[row][j] * t1) % 7 + 7) % 7;}}++row;++col;}for(int i = row; i < m; ++i){if(matrix[i][n] != 0){return -1;}}if(row == n && modify()){return 0;}return 1;}void output(){printf("%d", matrix[0][n]);for(int i = 1; i < n; ++i){printf(" %d", matrix[i][n]);}printf("\n");}int main(){while(input()){switch(gauss()){case -1:printf("Inconsistent data.\n");break;case 1:printf("Multiple solutions.\n");break;default:output();}}return 0;}
- 2974
- ZJU 2974
- POJ 2974 487-3279
- 4.3例题--487-3279--2974
- zoj 2974 矩阵连乘
- 【DP】 HDOJ 2974 Counting heaps
- 百练 OJ 2974 487 3279
- Zoj Just Pour the Water 2974
- ZOJ - 2974 Just Pour the Water
- POJ 百练 2974: 487-3279
- poj 百练2974(基础题)
- zoj 2974 Just Pour the Water
- zoj 2974 Just Pour the Water 矩阵
- POJ 3528 & POJ 2974 三维凸包
- ZOJ - 2974 Just Pour the Water
- ZOJ 2974Just Pour the Water
- ZOJ --- 2974 倒水 【思维 + 矩阵快速幂】
- [矩阵幂运算] ZOJ 2974 Just Pour the Water
- linux平台下 延迟工作队列实例
- zoj 2857 Image Transformation
- RHEL AS4 上oracle10gR2 静默安装
- 含有return 的try catch finally的执行顺序
- Windows 蓝屏代码详解
- 2974
- 磁盘空间的处理
- 用Column Family作为索引
- 无题
- 由坑爹的编译想起的
- ubuntu 11.10 Things to tweak after install
- 一个在MFC下使用的按钮美化类XPButton
- 加藤嘉一谈中国大学生
- 怎样才能做好技术团队管理