这套题我答的很失败。没有按照题目的难度去答题,前期浪费了不少时间。
题目:
A-字符画
题解:思维、模拟。这道题我的通过率为62.5,没有过的原因是因为对细节的处理和把控不到位,对一些点忽视,我也记录了搜索的过程,但没有把搜索过的点消掉,而且没有找到最好的顺序去解答这道题,我是按照横的方法去找字符,但是如果按照竖的方法去搜索的话,就能ac。
题目如下:
还有:
代码如下:
点击查看代码
#include<bits/stdc++.h>
#define endl '\n'
//#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int N = 2e5+10;
int n, m, k,sum1,sum2,sum3;
char a[505][505];
bool b[505][505];
bool check2(int x,int y){
if(b[x][y]==0) return true;
else return false;
}
void sovle(){
cin>>n>>m;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>a[i][j];
}
}
for(int i=0;i<m-2;i++){
for(int j=0;j<n-4;j++){
if(a[j][i]=='#'&&a[j+1][i]=='#'&&a[j+2][i]=='#'&&a[j+3][i]=='#'&&a[j+4][i]=='#'&&a[j][i+1]=='#'&&a[j+1][i+1]=='.'&&a[j+2][i+1]=='#'&&a[j+3][i+1]=='.'&&a[j+4][i+1]=='#'&&a[j][i+2]=='#'&&a[j+1][i+2]=='#'&&a[j+2][i+2]=='#'&&a[j+3][i+2]=='#'&&a[j+4][i+2]=='#'&&check2(j,i)&&check2(j+1,i)&&check2(j+2,i)&&check2(j+3,i)&&check2(j+4,i)&&check2(j,i+1)&&check2(j+1,i+1)&&check2(j+2,i+1)&&check2(j+3,i+1)&&check2(j+4,i+1)&&check2(j,i+2)&&check2(j+1,i+2)&&check2(j+2,i+2)&&check2(j+3,i+2)&&check2(j+4,i+2)){
sum3++;
b[j][i]=b[j+1][i]=b[j+2][i]=b[j+3][i]=b[j+4][i]=b[j][i+1]=b[j+1][i+1]=b[j+2][i+1]=b[j+3][i+1]=b[j+4][i+1]=b[j][i+2]=b[j+1][i+2]=b[j+2][i+2]=b[j+3][i+2]=b[j+4][i+2]=1;
}
else if(a[j][i]=='#'&&a[j+1][i]=='#'&&a[j+2][i]=='#'&&a[j+3][i]=='#'&&a[j+4][i]=='#'&&a[j][i+1]=='#'&&a[j+1][i+1]=='.'&&a[j+2][i+1]=='#'&&a[j][i+2]=='#'&&a[j+1][i+2]=='#'&&a[j+2][i+2]=='#'&&check2(j,i)&&check2(j+1,i)&&check2(j+2,i)&&check2(j+3,i)&&check2(j+4,i)&&check2(j,i+1)&&check2(j+1,i+1)&&check2(j+2,i+1)&&check2(j,i+2)&&check2(j+1,i+2)&&check2(j+2,i+2)){
sum1++;
b[j][i]=b[j+1][i]=b[j+2][i]=b[j+3][i]=b[j+4][i]=b[j][i+1]=b[j+1][i+1]=b[j+2][i+1]=b[j][i+2]=b[j+1][i+2]=b[j+2][i+2]=1;
}
else if(a[j][i]=='#'&&a[j][i+1]=='#'&&a[j+1][i+1]=='.'&&a[j+2][i+1]=='#'&&a[j][i+2]=='#'&&a[j+1][i+2]=='#'&&a[j+2][i+2]=='#'&&a[j+3][i+2]=='#'&&a[j+4][i+2]=='#'&&check2(j,i)&&check2(j,i+1)&&check2(j+1,i+1)&&check2(j+2,i+1)&&check2(j,i+2)&&check2(j+1,i+2)&&check2(j+2,i+2)&&check2(j+3,i+2)&&check2(j+4,i+2)){
sum2++;
b[j][i]=b[j][i+1]=b[j+1][i+1]=b[j+2][i+1]=b[j][i+2]=b[j+1][i+2]=b[j+2][i+2]=b[j+3][i+2]=b[j+4][i+2]=1;
}
}
}
cout<<sum1<<' '<<sum2<<' '<<sum3;
}
int main()
{
//ios::sync_with_stdio(false), cin.tie(0),cout.tie(0);
int t = 1;
//cin>>t;
while (t --){
sovle();
}
return 0;
}
代码如下:
点击查看代码
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> PII;
const int N=2e6+10;
int v[100001];
int c[100001];
int n;
bool check(int x)
{
for(int i=1;i<=n;i++){
if(x>v[i]+c[i])
{
x+=c[i]/2;
v[i+1]=(c[i]+1)/2;
}else
return 0;
}
return true;
}
signed main ()
{
int t=1;
//cin>>t;
while(t--)
{
cin>>n;
for(int i=1;i<=n;i++){
cin>>c[i];
}
v[1]=c[1];
long long r =1e12;
long long l =1;
while(l<r)
{
int mid=(l+r)>>1;
if(check(mid))
{
r=mid;
}else
{
l=mid+1;
}
}
cout<<l;
}
return 0;
}