前两题偏找规律,数学题,仔细点即可。最后一题超出了我的认知,直接交卷打游戏摆烂,现在到十点了贴下拙劣解法。
贴墙纸
纯找规律,最喜欢做这种题。。。
#include <iostream>
#include <vector>
using namespace std;
int main() {
int t;
cin>>t;
for (int k=0;k<t;k++) {
int n, m;
cin >> n >> m;
vector<vector<char>> flower(n, vector<char>(n));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> flower[i][j];
}
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < m; j++) {
int col = abs(abs(j - m / 2) - n / 2);
int row = abs(abs(i - m / 2) - n / 2);
if ((i < m / 2 - n / 2) || (i > m / 2 + n / 2)) row -= 1;
if ((j < m / 2 - n / 2) || (j > m / 2 + n / 2)) col -= 1;
cout << flower[row % n][col % n];
}
cout << endl;
}
cout<<endl;
}
}
矩形
暴力依次枚举两个矩形,累加重叠面积最后一起减去即可,顺便判断下孤立矩形。
#include <iostream>
#include <vector>
using namespace std;
int compute(int ax1,int ay1,int ax2,int ay2,int bx1,int by1,int bx2,int by2){
int oW=min(ax2,bx2)- max(ax1,bx1);
int oH=min(ay2,by2)- max(ay1,by1);
return max(oW,0)* max(0,oH);
}
int main(){
int t;
cin>>t;
for(int i=0;i<t;i++) {
int n;
cin >> n;
vector<vector<int>> nums(n, vector<int>(4));
for (int j = 0; j < n; j++) {
for (int k = 0; k < 4; k++) {
cin >> nums[j][k];
}
}
vector<int> count(n, n - 1);
long long overlap = 0;
for (int j = 0; j < n - 1; j++) {
for (int k = j + 1; k < n; k++) {
int area = compute(nums[j][0], nums[j][1], nums[j][2], nums[j][3], nums[k][0], nums[k][1], nums[k][2],nums[k][3]);
if (area == 0) {count[j]--;count[k]--;} else overlap += area;
}
}
long long sum = -overlap;
for (int j = 0; j < n; j++) {
if (count[j] > 0) sum += (nums[j][2] - nums[j][0]) * (nums[j][3] - nums[j][1]);
}
cout << sum << endl;
}
}
#秋招##2023届毕业生##网易笔试#