A题:Cakeminator
这题很水,直接上代码:
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
int main()
{
int r,c,r1=0,c1=0;
char a[20][20];
cin >> r >> c;
int i,j;
for(i=0; i<r; i++)
{
for(j=0; j<c; j++)
{
cin >> a[i][j];
}
}
for(i=0; i<r; i++)
{
for(j=0; j<c; j++)
{
if(a[i][j]!='.')
break;
}
if(j==c)
r1++;
}
for(i=0; i<c; i++)
{
for(j=0; j<r; j++)
{
if(a[j][i]!='.')
break;
}
if(j==r)
c1++;
}
cout << r1*c+c1*r-c1*r1 << endl;
return 0;
}
B题:Road Construction
题意:有n个城市,要求在各城市之间建桥,并且任意两个城市之间能够互相到达,并且最多走两座桥,再输入哪两城市不能建桥。输出要建多少座桥。和哪两个城市之间有桥。
思路:由于任一两座城市之间最多走两座桥,那么就是所有的城市都和一个能与任何城市相连的城市相连即可。
code:
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
int x,y;
int vis[1111]={0};
int main()
{
int n,m,i,t;
cin >> n >> m;
for(i=1;i<=m;i++)
{
cin >> x >> y;
vis[x]=vis[y]=1;
}
for(i=1;i<=n;i++)
{
if(vis[i]==0)
{
t=i;
break;
}
}
cout << n-1 << endl;
for(i=1;i<=n;i++)
{
if(i!=t)
cout << t << " " << i << endl;
}
return 0;
}
C题:Purification
这道题只要每行或者没列都存在‘ . ’即可。
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
using namespace std;
char a[111][111] ;
int v[111][111] = {{0}} ;
int x[111] = {0} , y[111] = {0} ;
int main()
{
int n , i , j ;
int num1 = 0 , num2 = 0 , f = 0 ;
cin >> n ;
for(i = 1 ; i <= n ; i ++)
{
for(j = 1 ; j <= n ; j ++)
{
cin >> a[i][j] ;
if(a[i][j] == 'E')
{
x[i] ++ ;
y[j] ++ ;
}
}
}
for(i = 1 ; i <= n ; i ++)
{
for(j = 1 ; j <= n ; j ++)
{
if(x[i] == n && y[j] == n)
{
f=1;
cout << -1 << endl ;
break;
}
}
if(f)
break;
}
if(!f)
{
for(i =1 ; i <= n ; i ++)
{
if(x[i] != n)
num1 ++ ;
if(y[i] != n)
num2 ++ ;
}
if(num1 == n)
{
for(i = 1 ; i <= n ; i ++)
{
int flag=0;
for(j = 1 ; j <= n ; j ++)
{
if(a[i][j] == '.')
{
cout << i << " " << j << endl ;
flag = 1 ;
}
if(flag)
break;
}
}
}
else if(num2 == n)
{
for(i = 1 ; i <= n ; i ++)
{
int flag1=0;
for(j = 1 ; j <= n ; j ++)
{
if(a[j][i] == '.')
{
cout << j << " " << i << endl ;
flag1 = 1 ;
}
if(flag1)
break;
}
}
}
}
return 0;
}
那天只做了三道题~~~后边两道还没有看~~