您的位置:首页 > 其它

Codeforces Round #108 (Div. 2)

2012-10-25 13:18 127 查看
比较悲剧的的比赛,做的题太少了,做比赛的时候还有一点紧张,比赛时思路有时候不是特别清楚,有的地方考虑太多,总的来说还是水平不够,加油。
A - Marks
给出n行数字,每行数字长为m;要求出这n行当中有几行拥有最大值(它的第i位比所有其他行的第i位都大或相等),只需要逐行比较就行了,找出每一列的最大的,然后找出和它相等的行;
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
char a[110][110];
int b[110];
int main()
{
int n,m;
while(cin>>n>>m)
{
memset(b,0,sizeof(b));

for(int i=1; i<=n; i++)
cin>>a[i];
for(int i=0; i<m; i++)
{
int max=0;
for(int j=1; j<=n; j++)
{
if(a[j][i]>max)
max=a[j][i];
}
for(int k=1; k<=n; k++)
if(a[k][i]==max)
b[k]=1;
}
int cnt=0;
for(int i=1;i<=n;i++)
if(b[i]) cnt++;
cout<<cnt<<endl;
}
return 0;
}
B - Steps(比赛中未作出来)
在(n*m)的board上,初始位置为(x,y),有k个方向移动,要求出在不出board最多能移动多少步,

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
typedef long long LL;
LL x,y;
int main()
{
//freopen(\"in.txt\",\"r\",stdin);
LL n,m,x0,y0,k,x1,y1;
while(cin>>n>>m)
{
cin>>x0>>y0>>k;
LL step=0;
for(LL i=0; i<k; i++)
{
cin>>x>>y;
if(x0+x<1||x0+x>n||y0+y<1||y0+y>m)continue;
if(x>0)
{
if(y>0)
{
x1=n-x0;
y1=m-y0;
}
else
{
x1=n-x0;
y1=y0-1;
}
}
else
{
if(y>0)
{
x1=x0-1;
y1=m-y0;
}
else
{
x1=x0-1;
y1=y0-1;
}
}

LL t,t1,t2;
if(x==0)
{
t=abs(y1/y);
step+=t;
y0+=t*y;
}
else if(y==0)
{
t=abs(x1/x);
step+=t;
x0+=t*x;
}
else
{
t1=abs(x1/x);
t2=abs(y1/y);
t=min(t1,t2);
step+=t;
x0+=t*x;
y0+=t*y;
}
}
cout<<step<<endl;
}
return 0;
}

C - Pocket books
只需找到每一列不同的字符个数,然后乘起来;
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
typedef long long LL;
char a[101][101];
LL b[101][127];
int main()
{
LL i,j,k,m,n,cnt;
while(cin>>n>>m)
{
for(int i=0;i<n;i++)
cin>>a[i];
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
b[i][a[j][i]]=1;
}
}
LL ans=1;
for(int i=0;i<m;i++)
{
cnt=0;
for(int j=0;j<127;j++)
if(b[i][j])
cnt++;
if(cnt)
ans*=cnt;
ans%=1000000007;
}
cout<<ans<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: