生活随笔
收集整理的這篇文章主要介紹了
Codeforces Round #777 (Div. 2)【未完结】
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
老年選手,做個(gè)簽到就溜了。
現(xiàn)在才開始補(bǔ)題,cf分一直上不去。
目錄
- A. Madoka and Math Dad【構(gòu)造】
- B. Madoka and the Elegant Gift【連通塊】
- C. Madoka and Childish Pranks【構(gòu)造】
A. Madoka and Math Dad【構(gòu)造】
其實(shí)通過(guò),樣例你可以發(fā)現(xiàn)規(guī)律,要么121...要么2121... 就看余數(shù)是不是1了。
#include<bits/stdc++.h>
using namespace std
;
int main(void)
{int t
; cin
>>t
;while(t
--){int n
; cin
>>n
;if(n
%3==1) {while(n
>=3) cout
<<"12",n
-=3;cout
<<n
;}else {while(n
>=3) cout
<<"21",n
-=3;if(n
) cout
<<n
;}puts("");}return 0;
}
B. Madoka and the Elegant Gift【連通塊】
就是判斷每一個(gè)連通塊是不是完美的矩形。
我的笨的方法,是直接暴力搜索,存一下左上角和右下角。
再二維前綴和求和??唇Y(jié)果和長(zhǎng)乘寬的結(jié)果一樣不一樣。
#include<bits/stdc++.h>
using namespace std
;
const int N
=210;
int t
,n
,m
,s
[N
][N
];
int dx
[4]={-1,0,0,1};
int dy
[4]={0,-1,1,0};
char a
[N
][N
];
int query(int x
,int y
,int xx
,int yy
)
{int sum
=s
[xx
][yy
]-s
[x
-1][yy
]-s
[xx
][y
-1]+s
[x
-1][y
-1];return sum
;
}
void dfs(int x
,int y
,int& x1
,int& y1
,int& x2
,int& y2
)
{a
[x
][y
]='0';x1
=min(x1
,x
),x2
=max(x2
,x
),y1
=min(y1
,y
),y2
=max(y2
,y
);for(int i
=0;i
<4;i
++){int tempx
=x
+dx
[i
];int tempy
=y
+dy
[i
];if(tempx
<=0||tempx
>n
||tempy
<=0||tempy
>m
) continue;if(a
[tempx
][tempy
]=='0') continue;dfs(tempx
,tempy
,x1
,y1
,x2
,y2
);}
}
int main(void)
{cin
>>t
;while(t
--){memset(s
,0,sizeof s
);cin
>>n
>>m
;for(int i
=1;i
<=n
;i
++)for(int j
=1;j
<=m
;j
++)cin
>>a
[i
][j
],s
[i
][j
]=a
[i
][j
]-'0';for(int i
=1;i
<=n
;i
++)for(int j
=1;j
<=m
;j
++)s
[i
][j
]+=s
[i
-1][j
]+s
[i
][j
-1]-s
[i
-1][j
-1];bool flag
=1;for(int i
=1;i
<=n
;i
++){for(int j
=1;j
<=m
;j
++){if(a
[i
][j
]=='1'){int x1
=1e9,y1
=1e9;int x2
=-1e9,y2
=-1e9;dfs(i
,j
,x1
,y1
,x2
,y2
);int temp
=query(x1
,y1
,x2
,y2
);int temp1
=(x2
-x1
+1)*(y2
-y1
+1);if(temp
!=temp1
) flag
=0;}}}if(flag
) puts("YES");else puts("NO");}return 0;
}
C. Madoka and Childish Pranks【構(gòu)造】
先用上圖從后往前構(gòu)造,那么除了第一行,都可以完美的構(gòu)造出來(lái)。
接下來(lái)就只看第一行。
上圖,從右往左走。
md的因?yàn)橛肅lang++17交,一直T,后來(lái)才發(fā)現(xiàn)交錯(cuò)編譯器了。
#include<bits/stdc++.h>
using namespace std
;
const int N
=210;
int t
,n
,m
;
char a
[N
][N
];
struct node
{int a
,b
,c
,d
;};
int main(void)
{std
::ios
::sync_with_stdio(false);std
::cin
.tie(0);cin
>>t
;while(t
--){cin
>>n
>>m
;for(int i
=0;i
<n
;i
++) for(int j
=0;j
<m
;j
++) cin
>>a
[i
][j
];if(a
[0][0]=='1'){cout
<<"-1"<<'\n';continue;}vector
<node
>ve
;for(int i
=n
-1;i
>=1;i
--)for(int j
=0;j
<m
;j
++) if(a
[i
][j
]=='1') ve
.push_back({i
-1,j
,i
,j
});for(int i
=m
-1;i
>=1;i
--)if(a
[0][i
]=='1') ve
.push_back({0,i
-1,0,i
});cout
<<ve
.size()<<'\n';for(int i
=0;i
<ve
.size();i
++)cout
<<ve
[i
].a
+1<<" "<<ve
[i
].b
+1<<" "<<ve
[i
].c
+1<<" "<<ve
[i
].d
+1<<'\n';}return 0;
}
《新程序員》:云原生和全面數(shù)字化實(shí)踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀
總結(jié)
以上是生活随笔為你收集整理的Codeforces Round #777 (Div. 2)【未完结】的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。