R39场题解
2025-2-12 10:48:42
~赚了多少钱
题解
其实就是只要不是隐藏款 把差价加上去,然后遇到了隐藏款,花 元,退出循环即可。记得使用 。
标程
long long n, m, a[10], ans, x;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for(int i = 1; i <= 6; i++) cin >> a[i];
for(int i = 1; i <= n; i++)
{
cin >> x;
if(x != 7) ans += (a[x] - m);
else
{
ans -= m;
break;
}
}
cout << ans << '\n';
return 0;
}
TooY0ung用计算器
题解
提前把两个数字的步数存起来,可以打个表,然后直接求和即可。或者也可以用某些数学规律直接计算,但是显然没有打表简单粗暴。
标程
int a[10][10] =
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 2, 1, 2, 3, 2, 3, 4,
0, 1, 0, 1, 2, 1, 2, 3, 2, 3,
0, 2, 1, 0, 3, 2, 1, 4, 3, 2,
0, 1, 2, 3, 0, 1, 2, 1, 2, 3,
0, 2, 1, 2, 1, 0, 1, 2, 1, 2,
0, 3, 2, 1, 2, 1, 0, 3, 2, 1,
0, 2, 3, 4, 1, 2, 3, 0, 1, 2,
0, 3, 2, 3, 2, 1, 2, 1, 0, 1,
0, 4, 3, 2, 3, 2, 1, 2, 1, 0
};
string s;
int ans;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> s;
int siz = (int)s.size();
s = "1" + s;
for(int i = 1; i <= siz; i++)
{
int x = s[i - 1] - '0';
int y = s[i] - '0';
ans += a[x][y];
}
cout << ans << '\n';
return 0;
}
数数几个L
题解
是个模拟,先找到竖着的矩形,然后横着找一下有没有就行了。
标程
#include <bits/stdc++.h>
using namespace std;
int n,mp[30][30],c=0;
bool check(int x,int y,int f){
int sx=x,sy=y,fx=x,fy=y;//上下x 上下y
while(mp[sx-1][y]==1) sx--;
while(mp[fx+1][y]==1) fx++;
while(mp[x][sy-1]==1) sy--;
while(mp[x][fy+1]==1) fy++;
if(f==1){//左上角空
if(fx-x!=fy-y) return false;
for(int i=sx;i<=fx;i++){
for(int j=sy;j<=fy;j++){
if(i<x&&j<y){
if(mp[i][j]==1) return false;
}else{
if(mp[i][j]!=1) return false;
if(i==sx) if(mp[i-1][j]==1) return false;
if(i==fx) if(mp[i+1][j]==1) return false;
if(j==sy) if(mp[i][j-1]==1) return false;
if(j==fy) if(mp[i][j+1]==1) return false;
}
}
}
return true;
}
if(f==2){//右上角空
if(fx-x!=y-sy) return false;
for(int i=sx;i<=fx;i++){
for(int j=sy;j<=fy;j++){
if(i<x&&j>y){
if(mp[i][j]==1) return false;
}else{
if(mp[i][j]!=1) return false;
if(i==sx) if(mp[i-1][j]==1) return false;
if(i==fx) if(mp[i+1][j]==1) return false;
if(j==sy) if(mp[i][j-1]==1) return false;
if(j==fy) if(mp[i][j+1]==1) return false;
}
//cout<<i<<" "<<j<<" "<<mp[i][j]<<endl;
}
}
return true;
}
if(f==3){//右下角空
if(x-sx!=y-sy) return false;
for(int i=sx;i<=fx;i++){
for(int j=sy;j<=fy;j++){
if(i>x&&j>y){
if(mp[i][j]==1) return false;
}else{
if(mp[i][j]!=1) return false;
if(i==sx) if(mp[i-1][j]==1) return false;
if(i==fx) if(mp[i+1][j]==1) return false;
if(j==sy) if(mp[i][j-1]==1) return false;
if(j==fy) if(mp[i][j+1]==1) return false;
}
}
}
return true;
}
if(f==4){//左下角空
if(x-sx!=fy-y) return false;
for(int i=sx;i<=fx;i++){
for(int j=sy;j<=fy;j++){
if(i>x&&j<y){
if(mp[i][j]==1) return false;
}else{
if(mp[i][j]!=1) return false;
if(i==sx) if(mp[i-1][j]==1) return false;
if(i==fx) if(mp[i+1][j]==1) return false;
if(j==sy) if(mp[i][j-1]==1) return false;
if(j==fy) if(mp[i][j+1]==1) return false;
}
}
}
return true;
}
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
char c;
cin>>c;
if(c=='*') mp[i][j]=1;
else mp[i][j]=0;
}
}
int cnt=0;
for(int i=1;i<n;i++){
for(int j=1;j<n;j++){
if(mp[i][j]==0&&mp[i][j+1]==1&&mp[i+1][j+1]==1&&mp[i+1][j]==1){
if(check(i+1,j+1,1)){
// cout<<i+1<<" "<<j+1<<" "<<"f1"<<endl;
cnt++;
}
}
if(mp[i][j]==1&&mp[i][j+1]==0&&mp[i+1][j+1]==1&&mp[i+1][j]==1){
if(check(i+1,j,2)){
// cout<<i+1<<" "<<j<<" "<<"f2"<<endl;
cnt++;
}
}
if(mp[i][j]==1&&mp[i][j+1]==1&&mp[i+1][j+1]==0&&mp[i+1][j]==1){
if(check(i,j,3)){
// cout<<i<<" "<<j<<" "<<"f3"<<endl;
cnt++;
}
}
if(mp[i][j]==1&&mp[i][j+1]==1&&mp[i+1][j+1]==1&&mp[i+1][j]==0){
if(check(i,j+1,4)){
//cout<<i<<" "<<j+1<<" "<<"f4"<<endl;
cnt++;
}
}
}
}
cout<<cnt;
}
数数几个Z
题解
模拟,先找到一个横,然后从左边或者右边,找一下斜线,然后再反方向找横就行了。
标程
#include<bits/stdc++.h>
using namespace std;
int n, ans;
char mp[1005][1005];
bool check(int x, int y, int len) {
int ch = 0, cl = 0, cd = 0;
bool f1 = 0, f2 = 0, f3 = 0, f4 = 0, f5 = 0, f6 = 0;
for (int i = y; i <= y + len - 1; i++) {
if (mp[x][i] == '.') {
f1 = 1;
break;
}
}
if (!f1) {
ch++;
}
for (int i = y; i <= y + len - 1; i++) {
if (mp[x + len - 1][i] == '.') {
f2 = 1;
break;
}
}
if (!f2) {
ch++;
}
for (int i = x; i <= x + len - 1; i++) {
if (mp[i][y] == '.') {
f3 = 1;
break;
}
}
if (!f3) {
cl++;
}
for (int i = x; i <= x + len - 1; i++) {
if (mp[i][y + len - 1] == '.') {
f4 = 1;
break;
}
}
if (!f4) {
cl++;
}
for(int k=0;k<len;k++){
if (mp[x+k][y+k] == '.') {
f5 = 1;
break;
}
}
if (!f5) {
cd++;
}
for(int k=0;k<len;k++){
if (mp[x+k][y+len-1-k] == '.') {
f6 = 1;
break;
}
}
if (!f6) {
cd++;
}
//cout<<ch<<' '<<cl<<' '<<cd<<"\n";
int cnt = 0;
for (int i = x; i <= x + len - 1; i++) {
for (int j = y; j <= y + len - 1; j++) {
if (mp[i][j] == '*') {
cnt++;
}
}
}
if (len == 3) {
if (((ch == 2 && cl == 0 && cd == 2) || (ch == 0 && cl == 2 && cd == 2))&& cnt == 3 * len - 2) {
return true;
}
} else if (((ch == 2 && cl == 0 && cd == 1) || (ch == 0 && cl == 2 && cd == 1)) && cnt == 3 * len - 2) {
return true;
}
return false;
}
int main() {
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> mp[i][j];
}
}
//cout<<check(1, 2, 3);
for (int len = 3; len <= n; len++) {
for (int i = 1; i + len - 1 <= n; i++) {
for (int j = 1; j + len - 1 <= n; j++) {
if (check(i, j, len)) {
ans++;
}
}
}
}
cout << ans << "\n";
return 0;
}
我们会审查剪贴板内容,并对发布不合适内容的同学进行相应的处理