A题
http://codeforces.com/problemset/problem/6/B水
#include<bits/stdc++.h>
#include<cstring>
//#include<map>
using namespace std;
//map<char,int>mp;
int main()
{
int n,m,ans=0,b[110];
char a[110][110];
char c;
int i,j;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
cin>>n>>m;
cin>>c;
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
cin>>a[i][j];
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
if(a[i][j]==c)
{
if(a[i-1][j]!=c)
b[a[i-1][j]-'A']++;
if(a[i+1][j]!=c)
b[a[i+1][j]-'A']++;
if(a[i][j-1]!=c)
b[a[i][j-1]-'A']++;
if(a[i][j+1]!=c)
b[a[i][j+1]-'A']++;
}
}
}
for(i=0;i<26;i++)
{
//cout<<b[i];
if(b[i]!=0)
ans++;
}
cout<<ans<<endl;
return 0;
}
B 绕了好久都绕自闭了(i++ 先用再加
http://codeforces.com/problemset/problem/6/C
#include<iostream>
using namespace std;
const int maxn=1e5+10;
int a[maxn];
int main()
{
int n,i,j,ans=0,num=0,k=0,t=0;
cin>>n;
for(i=1;i<=n;i++)
cin>>a[i];
i=1;
j=n;
while(i<=j)
{
if(ans<=num)
{
ans+=a[i++];
k++;
}
else
{
num+=a[j--];
//cout<<j<<" j"<<endl;
t++;
}
}
cout<<k<<" "<<t<<endl;
return 0;
}
D 题 (折磨人
https://codeforces.com/problemset/problem/8/B
判断走的路是否是最短路
#include<bits/stdc++.h>
#include<cstring>
using namespace std;
int a[550][550];
int main()
{
char s[110];
int i,j,l,flag=0,k;
memset(a,0,sizeof(a));
cin>>s;
l=strlen(s);
i=200;
j=200;
//cout<<a[i][j]<<a[i][j+1];
for(k=0;k<l;k++)
{
a[i][j]=1;
if(s[k]=='L')
{
j--;
}
if(s[k]=='R')
{
j++;
}
if(s[k]=='U')
{
i++;
}
if(s[k]=='D')
{
i--;
}
if(a[i][j]+a[i-1][j]+a[i][j-1]+a[i+1][j]+a[i][j+1]>1)
{
cout<<"BUG"<<endl;
return 0;
}
}
cout<<"OK"<<endl;
return 0;
}