华中农大HZAUOJ 1097 1099 BFS、数据类型小心

1097:Yuchang and Zixiang ‘s maze

Time Limit: 2 Sec   Memory Limit: 128 MB
Submit: 937   Solved: 166
[ Submit][ Status][ Web Board]

Description

One day ,  Yuchang and Zixiang go out of school to find some thing interesting . But both of them is LuChi , so the miss the way easily .
“Where am I ? who am I ?” Yuchang says . “Who attack you? You must want to say .” Zixiang adds . “Don’t say that , how we get out there ? I want my mom 555555……” Yuchang started crying . Zixiang become very panic . He doesn’t know how to get out there.
 Now , they find they are in a N*M maze , they are at the (a,b) point , they know they want to go to the point (c,d) , they want to finish as soon as possible, so , could you help them ?
Same as other maze , there are some point has boom , means they can’t get the point . Give you N,M and Num (the number of points that have booms . ) , then , Num lines contains pairs (x,y) means point (x,y) have booms . then , one line contains a , b , c , d ,the begin and end point .
They can mov forward , back , left and right . And every move cost 1 second . Calculate how many seconds they need to get to the finish point .

Input

The first line contains tow numbers N,M (0 < x,y < 1000)means the size of the maze.
The second line contains a number Num (0 < N < X*Y), means the number of points which have booms .
Then next N lines each contain two numbers , xi,yi , means (xi,yi)  has a boom .

Output

One line , contains one number , the time they cost .
    If they can’t get to the finish point , output -1 .

Sample Input

1000 1000 4
5 5
5 7
4 6
6 6 
1 1 5 6

Sample Output

-1

正正堂堂的bfs:

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
using namespace std;
const int maxn = 1010;
const int INF = 0x3f3f3f3f;
bool save[maxn][maxn];
int d[maxn][maxn];
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
int n,m;
pair<int, int> s,e;
int bfs(){
    int i,j;
    queue<pair<int, int> > que;
    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++){
            d[i][j]=INF;
        }
    }
    que.push(s);
    d[s.first][s.second] = 0;
    while(que.size()){
        pair<int, int> p=que.front();
        que.pop();
        if(p.first==e.first&&p.second==e.second){
            break;
        }
        for(i=0;i<4;i++){
            int nx=p.first+dx[i] , ny=p.second+dy[i];
            if(1<=nx&&nx<=n&&ny>=1&&ny<=m&&save[nx][ny]&&d[nx][ny]==INF){
                que.push(make_pair(nx, ny));
                d[nx][ny]=d[p.first][p.second]+1;
            }
        }
    }
    return d[e.first][e.second];
}
int main(){
    int num;
    int i,j,k,a,b;
    while(~scanf("%d%d%d",&n,&m,&num)){
        memset(save, true, sizeof(save));
        for(i=1;i<=num;i++){
            scanf("%d%d",&a,&b);
            save[a][b] = false;
        }
        scanf("%d%d",&a,&b);
        s = make_pair(a, b);
        scanf("%d%d",&a,&b);
        e = make_pair(a, b);
        int res = bfs();
        if(res==INF){
            printf("-1\n");
        }else{
            printf("%d\n",res);
        }
    }
    return 0;
}

1099: Die Die Die!

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 3639   Solved: 510
[ Submit][ Status][ Web Board]

Description

do not play Overwatch
do not not play Overwatch
do not play Overwatch
do not not play Overwatch
the game will consume your soul
and drag you to the depth of hell
I'm not f**king joking around bro
I woke up at nine pm dawg
this game is not f**king joke bro
I stayed up till five pm dawg
this is a f**king problem dawg
what the f**k did Blizzard do to make it so addictive
I never play no Diablo
I never play no World of Warcraft
I never f**k with no Hearthstone
who give a f**k about the Heroes of the Storm
and you god damn bitches sweet ass 
that ya boy never put his dick anywhere near no Starcraft
but Overwatch
Overwatch
What the f**k's in Overwatch!
But you are still playing Overwatch ~2333333333,and now you control a character who‘s name is Reaper. The most powerful skill of him is called Death Blossom, when he use this skill, Reaper will shot around to kill his enemy. Here is the question, you want to know the area of the skill that Reaper can kill his enemy. We assume that each time when Reaper using this skill, he will never move, so we can suppose that he is a point, and the bullets which he shots will fly L meters, because he is so fast that he can shot 360 degrees around him. Now, please tell me the area of his skill. To make it more interesting, you must just print n bits after decimal point.

Input

The input file will contain several tests,it will end with EOF, each test contain two integers L and n .(0<=L<=25,0<=n<=6)

Output

Your answer .Please notice that when your answer is 0, as you can see 0 is the same to 0.0 or 0.00 or 0.000 ……, so you should just print 0. And when the n is 0, you should not print decimal point.

Sample Input

1 0
1 1
1 4

Sample Output

3
3.1
3.1415 

HINT

这题很有意思,我原先觉得写的没错的代码wa了好久,明明是个全场题。。

原先wa的代码:

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <iomanip>
using namespace std;
const int maxn = 1010;
double pi = 3.1415926535897932384626433832795023841971693993751058209749445923078164062862;
int main(){
    double l;
    int n;
    while(~scanf("%lf%d",&l,&n)){
        if((int)l==0){
            printf("0\n");
            continue;
        }
        double res = pi*l*l;
        double now = res * pow(10, n+1);
        if(((int)now%10)>=5){
            res -= (0.5*pow(10,-n));
        }
        cout << fixed << setprecision(n) << res << endl;
    }
    return 0;
}

因为fixed+setprecision(n)是用来四舍五入地输出小数点后n位的。而题目的意思是不需要四舍五入,直接输出即可。于是我就判断第n+1位是否大于5,若大于5就减去0.5*10e-n搞一个精度。居然wa了!!!

于是开始研究。。。。问题就出在这里。。。

now是由res*pow(10,n+1)得来的。。。n最大是6,所以pow这玩意儿不会超过1e7,但是res是会大于三位数的,这就可以成功爆掉int,然后判精度的时候就会出问题。

还是自己对各个数据类型没有完备的思考。。。。不熟练啊

ac代码:

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <iomanip>
using namespace std;
const int maxn = 1010;
double pi = 3.1415926535897932384626433832795023841971693993751058209749445923078164062862;
int main(){
    double l,i;
    int n;
    while(~scanf("%lf%d",&l,&n)){
        if((int)l==0){
            printf("0\n");
            continue;
        }
        double res = pi*l*l;
        if(n==0){
            printf("%d\n",(int)res);
        }else{
            cout<<(int)res<<".";
            for(i=1;i<=n;i++){
                cout<<((int)(res * pow(10, i))%10);
            }
            cout<<endl;
        }
    }
    return 0;
}













评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值