C. Perfect Square(矩形旋转之后对应的坐标)

  题目:  https://codeforces.com/contest/1881/problem/C

  思路: 

 旋转之后对应的坐标:

顺时针旋转 0 90 180 270 分别为(i,j)(j,n+1-i)(n+1-i,n+1-j)(n+1-j,i)

 代码:

// Problem: C. Perfect Square
// Contest: Codeforces - Codeforces Round 903 (Div. 3)
// URL: https://codeforces.com/contest/1881/problem/C
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include
using namespace std;

typedef long long ll;

const int N = 1e3+3;

int n;
char a[N][N];

int main(){
	int T;
	cin>>T;
	while(T--){
		cin>>n;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				cin>>a[i][j];
			}
		}	
		
		int ans=0;
		for(int i=1;i<=n/2;i++){
			for(int j=1;j<=n/2;j++){
				vector v{a[i][j],a[n+1-j][i],a[n+1-i][n+1-j],a[j][n+1-i]};
				char c=*max_element(v.begin(),v.end());
				for(char x:v){
					ans+=c-x;
				} 
			}
		}
		cout<

你可能感兴趣的:(算法)