HDU4708 Rotation Lock Puzzle 不错的模拟题

题意:给你一个n*n的矩阵,n为奇数,以最中心的一个数为基准,可以把这个矩阵 看成一圈一圈的,每一圈都可以逆时针或者顺时针旋转,每一次旋转每个元素只能移动一个单元格,求经过每一圈的旋转矩阵两个对角线和最大的值,并求出最少旋转次数

一圈一圈的处理,注意最中心的那个数不用管,就它一个,那么这个矩阵只有n/2圈需要操作,对于每一圈的元素都放在一个一维数组里面,然后枚举这个数组里的每一个元素为开头,统计接下来的三个数,求和比较大小即可,因为有逆时针的,所以顺时针时从开头开始枚举,逆时针则从尾部开始枚举,这题数据貌似有些烂,

int n;

int mp[15][15];

void init() {
	memset(mp,0,sizeof(mp));
}

bool input() {
	while(cin>>n,n) {
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
				cin>>mp[i][j];
		return false;
	}
	return true;
}

void cal() {
	int ans = 0;
	int cnt = 0;
	int nnum = n/2;
	int aa[100 + 55];
	for(int k=0;k<nnum;k++) {
		memset(aa,0,sizeof(aa));
		int pos = 0;
		int sum = 0;
		int now = 0;
		for(int j=k;j<n - k;j++)aa[pos++] = mp[k][j];
		for(int i=k + 1;i<n - k;i++)aa[pos++] = mp[i][n - k - 1];
		for(int j=n - k - 2;j >k;j--)aa[pos++] = mp[n - k - 1][j];
		for(int i=n - k - 1;i>k;i--)aa[pos++] = mp[i][k];
		for(int i=0;i<=(pos + 1)/2;i++) {
			int tmp = 0;
			tmp = aa[i%pos] + aa[(i+(n-2*k-1))%pos] + aa[(i+2*(n-2*k-1))%pos] + aa[(i+3*(n-2*k-1))%pos];
			if(tmp > sum) {
				sum = tmp;
				now = i;
			}
			if(tmp == sum) {
				if(i < now)
					now = i;
			}
		}
		for(int i=pos-1,mark = 0;mark <=(pos+1)/2;i--) {
			int tmp = 0;
			tmp = aa[i%pos] + aa[(i+(n-2*k-1))%pos] + aa[(i+2*(n-2*k-1))%pos] + aa[(i+3*(n-2*k-1))%pos];
			if(tmp > sum) {
				sum = tmp;
				now = pos - i;
			}
			if(tmp == sum) {
				if(pos - i < now)
					now = pos - i;
			}
			mark++;
		}
		ans += sum;
		cnt += now;
	}
	ans += mp[n/2][n/2];
	cout<<ans<<" "<<cnt<<endl;
}

void output() {

}

int main() {
	while(true) {
		init();
		if(input())return 0;
		cal();
		output();
	}
	return 0;
}
时间: 2024-10-13 11:41:19

HDU4708 Rotation Lock Puzzle 不错的模拟题的相关文章

HDU 4708 Rotation Lock Puzzle (贪心+模拟)

Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1668    Accepted Submission(s): 530 Problem Description Alice was felling into a cave. She found a strange door with a number

hduoj 4708 Rotation Lock Puzzle 2013 ACM/ICPC Asia Regional Online —— Warmup

http://acm.hdu.edu.cn/showproblem.php?pid=4708 Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description Alice was felling into a cave. She found a strange door with a number square m

HDU 4708 Rotation Lock Puzzle(数学啊)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4708 Problem Description Alice was felling into a cave. She found a strange door with a number square matrix. These numbers can be rotated around the center clockwise or counterclockwise. A fairy came an

HDU 4708 Rotation Lock Puzzle

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4708 测试数据: 51 9 9 1 11 9 9 9 99 9 9 9 99 9 9 9 11 1 9 9 1 81 1 1 #include<iostream> 2 #include<algorithm> 3 #include<cstdio> 4 using namespace std; 5 long long a[15][15]; 6 long long step,an

hdu 5641 King&#39;s Phone(暴力模拟题)

Problem Description In a military parade, the King sees lots of new things, including an Andriod Phone. He becomes interested in the pattern lock screen. The pattern interface is a 3×3 square lattice, the three points in the first line are labeled as

锦程网考试由试题从模拟题中批量找出答案,Python

jincin的考试又来了,像往常一样会先有模拟题发下来,而考试题目几乎都在里面原题. 本来是,在考试时,把题目一题一题地在模拟题里搜,但觉得太累了. 于是写了一个Python的脚本批量查找,用到正则,由于不知道行尾是\r还是\n还是\r\n,干脆也用正则,而非split('\r')这么硬板了. 添了颜色,效果不错. Python: 效果: - 锦程网考试由试题从模拟题中批量找出答案,Python,布布扣,bubuko.com

HDU 4772 Zhuge Liang&#39;s Password (简单模拟题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4772 题面: Zhuge Liang's Password Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1404    Accepted Submission(s): 926 Problem Description In the anc

更新 | 2019年9月计算机二级office模拟题库

随着2019年上半年计算机二级考试的完美落幕,紧接着的便是9月份的考试了. 到目前为止,下半年9月份计算机二级考试报名开通时间在6月前后,现在也基本结束. 2019年9月(56次)全国计算机等级考试(以下简称NCRE)将于9月中旬举行.已经报名的同学请利用暑期时间好好准备吧! > 2019年9月份最新二级题库看文末 ▼ 公众号内回复关键词:2305获取下载链接 考前学习 计算机二级考试方法为机考,时间为120分钟,分数100分.得60分以上则通过考试. || 好好打基础,温习知识点 不管是自学考

HDU 4028 The time of a day STL 模拟题

暴力出奇迹.. #include<stdio.h> #include<iostream> #include<algorithm> #include<vector> #include<cmath> #include<queue> #include<set> #include<map> using namespace std; #define ll __int64 #define N 42 ll n,m,ans;