目录
过了两道题,继续加油
A Madoka and Math Dad
#include<bits/stdc++.h>
using namespace std;
int T;
int get1(int x){
return x % 3;
}
int get2(int x){
return x / 3;
}
int main()
{
cin>>T;
while(T -- ){
int n;
cin>>n;
int x = get1(n);
int y = get2(n);
if(x == 1){
cout<<"1";
for(int i = 0; i < 2 * y; i ++ ){
if(i % 2 == 0){
cout<<"2";
}
else if(i % 2 == 1){
cout<<"1";
}
}
}
else if(x == 2){
for(int i = 0; i < 2 * y; i ++ ){
if(i % 2 == 0){
cout<<"2";
}
else if(i % 2 == 1){
cout<<"1";
}
}
cout<<"2";
}
else if(x == 0){
for(int i = 0; i < 2 * y; i ++ ){
if(i % 2 == 0){
cout<<"2";
}
else if(i % 2 == 1){
cout<<"1";
}
}
}
cout<<endl;
}
return 0;
}
B Madoka and the Elegant Gift
注意对题中条件进行转化,不要一味的跟着题走,例如这道题让你判断是否有相交的矩形,其实就是判断是否有0附近存在拐角三角形
#include<bits/stdc++.h>
using namespace std;
const int N = 105;
typedef pair<int, int>PII;
char r1[N][N];
int T;
int n, m;
int dx1[3] = {0, -1, -1};
int dy1[3] = {-1, -1, 0};
int dx2[3] = {-1, -1, 0};
int dy2[3] = {0, 1, 1};
int dx3[3] = {0, 1, 1};
int dy3[3] = {1, 1, 0};
int dx4[3] = {1, 1, 0};
int dy4[3] = {0, -1, -1};
bool check(int x, int y){
int x1 = 0, x2 = 0, x3 = 0, x4 = 0;
for(int i = 0; i < 3; i ++ ){
int a = x + dx1[i], b = y + dy1[i];
if(a <= n && a >= 1 && b >= 1 && b <= m){
if(r1[a][b] == '1'){
x1 ++ ;
}
}
}
for(int i = 0; i < 3; i ++ ){
int a = x + dx2[i], b = y + dy2[i];
if(a <= n && a >= 1 && b >= 1 && b <= m){
if(r1[a][b] == '1'){
x2 ++ ;
}
}
}
for(int i = 0; i < 3; i ++ ){
int a = x + dx3[i], b = y + dy3[i];
if(a <= n && a >= 1 && b >= 1 && b <= m){
if(r1[a][b] == '1'){
x3 ++ ;
}
}
}
for(int i = 0; i < 3; i ++ ){
int a = x + dx4[i], b = y + dy4[i];
if(a <= n && a >= 1 && b >= 1 && b <= m){
if(r1[a][b] == '1'){
x4 ++ ;
}
}
}
if(x1 == 3 || x2 == 3 || x3 == 3 || x4 == 3) return false;
else return true;
}
vector<PII>res;
int main()
{
cin>>T;
while(T -- ){
cin>>n>>m;
for(int i = 1; i <= n; i ++ ){
for(int j = 1; j <= m; j ++ ){
cin>>r1[i][j];
if(r1[i][j] == '0'){
res.push_back({i, j});
}
}
}
bool flag = true;
for(auto ve : res){
if(!check(ve.first, ve.second)){
flag = false;
break;
}
}
res.clear();
if(!flag) cout<<"NO"<<endl;
else if(flag) cout<<"YES"<<endl;
}
return 0;
}