SDUT_2012省赛选拔赛1

A:bfs+优先队列。。。。第一天只能感染defence小于等于1的并且与之连接的机器,第二天只能感染defence小于等于2的并且与之连接的机器.。。。。。依次往后推。

View Code
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#define maxn 505
using namespace std;

int g[maxn][maxn],ct[maxn*maxn];
int dir[4][2] = {{0,1},{0,-1},{1,0},{-1,0}};
struct node
{
int x,y;
int type;
int day;
friend bool operator < (const node &a,const node &b)
{
if (a.day != b.day) return a.day > b.day;
else return a.type > b.type;
}
};
priority_queue<node>q;
int n,m;
void init()
{
int i,j;
memset(ct,0,sizeof(ct));
while (!q.empty()) q.pop();
for (i = 0; i < n; ++i)
{
for (j = 0; j < m; ++j)
{
scanf("%d",&g[i][j]);
if (g[i][j] > 0)
{
node p;
p.x = i; p.y = j;
p.type = g[i][j];
ct[p.type]++;
p.day = 1;
q.push(p);
}
}
}
}
void bfs()
{
int i;
while (!q.empty())
{
node pos = q.top();
q.pop();
node p;
int d = -9999999;
for (i = 0; i < 4; ++i)
{
p.x = pos.x + dir[i][0];
p.y = pos.y + dir[i][1];
if (p.x >= 0 && p.x < n && p.y >= 0 && p.y < m)
{
if (g[p.x][p.y] < 0)
{
if (g[p.x][p.y] + pos.day >= 0)
{
p.type = pos.type;
p.day = pos.day;
g[p.x][p.y] = pos.type;
q.push(p);
ct[pos.type]++;
}
else
{
if (g[p.x][p.y] > d)//这里不好理解,每次要记住该点最早所能感染的机器的天数
{
d = g[p.x][p.y];
}
}
}
}
}
if (d != -9999999)
{
pos.day = -d;
q.push(pos);
}
}
}
int main()
{
int t,num;
while (~scanf("%d%d",&n,&m))
{
init();
bfs();
scanf("%d",&t);
while (t--)
{
scanf("%d",&num);
printf("%d\n",ct[num]);
}
}
return 0;
}

B:von做的。。。

C:简单的统计'\t'以及空格的个数,开始von叫了好几次都是wa不知道哪错了,然后重写一遍就a了。

D,E,F没做出来

G:看了很长时间才看懂的题意,才开始我以为只要用经纬度计算就可以了,可是敲完代码后,结果不对,我就根据公式,将经纬度转化成x,y最后1Y..

View Code
#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
#include <cmath>
using namespace std;
const double pi = acos(-1.0);

int main()
{
double lo,la;
double x,y;
int level;
while (~scanf("%lf%lf%d",&lo,&la,&level))
{

x = 180 * pi / 180;
y = log(tan(pi / 4 + (85 * pi / 180) / 2)*1.0);
double tx = lo * pi / 180;
double ty = log(tan(pi / 4 + (la * pi / 180) / 2)*1.0);
// printf("%.2lf %.2lf\n",x,y);
//记录横向纵向的长度,以后每次往下分时,直接除以二就好了
double lenx = abs(x);
double leny = abs(y);
printf("t");
x = 0; y = 0;
while (level--)
{
//printf("%.2lf %.2lf\n",x,y);
if (tx < x && ty > y)//在左上角
{
printf("q");
x = (-lenx/2 + x);
y = (leny/2 + y);
}
else if (tx > x && ty > y)//在右上角
{
printf("r");
x = (lenx/2 + x);
y = (leny/2 + y);
}
else if (tx < x && ty < y )//在左下角
{
printf("t");
x = (-lenx/2 + x);
y = (-leny/2 + y);
}
else if (tx > x && ty < y )//在右下角
{
printf("s");
x = (lenx/2 + x);
y = (-leny/2 + y);
}
lenx /= 2;
leny /= 2;
//printf("\n");
}
printf("\n");
}
return 0;
}

F:应该是最简单的一道题,可是自己理解错题意了,wa了一次,然后看了好几遍才懂。。唉,。。英语不行啊。。

View Code
#include <cstdio>
#include <cstring>
#include <queue>
#include <iostream>
#define maxn 107
using namespace std;

int a[4][maxn][maxn];
int aa[maxn][maxn];
int n,m;
int main()
{
int i,j,k;
int num[5];
int cas = 1;
while (~scanf("%d%d",&n,&m))
{
if (!n && !m) break;
memset(num,0,sizeof(num));
for (k = 0; k < 3; ++k)
{
for (i = 0; i < n; ++i)
{
for (j = 0; j < m; ++j)
{
scanf("%d",&a[k][i][j]);
}
}
}
printf("Case %d:\n",cas++);
for (i = 0; i < n; ++i)
{
printf("%d",(a[0][i][0] + a[1][i][0] + a[2][i][0])/3);
for (j = 1; j < m; ++j)
{
printf(",%d",(a[0][i][j] + a[1][i][j] + a[2][i][j])/3);
}
printf("\n");
}

}
return 0;
}






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值