【正解】Openjudge 至少有多少只恼人的大青蛙 (dfs 剪枝 好题)

题目大意

http://cxsjsx.openjudge.cn/2015finalpractice/43/
讲真这题的大意我真的真的概括不来,各位看官老爷还是直接在原题目上看吧,顺便给出一个提交的链接。


题解

作为一道擅长屎题 向往屎题 热爱屎题的选手,不得不说,这道题确是一道搜索好(shi)题,所考察的搜索剪枝相关的知识点也是非常的全面。没有比较就没有差距,首先我放上一份无脑而又暴力的代码上来。

暴力代码 (哇这代码真他妈丑)

#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;

struct Point { //存储稻田中被糟蹋的坐标
    int x,y;
    Point() {}
    Point(int _x,int _y):x(_x),y(_y) {}
    bool operator < (const Point &b) const {
        if(x!=b.x) return x<b.x;
        return y<b.y;
    }
}p[1005];

const int maxn=55;
int n,m,k;
int Map[maxn][maxn];
int sum;

inline bool inrange(const int &x,const int &y) {
    if(x<1 || y<1 || x>n || y>m) return false;
    return true;
}

int lit;
bool dfs(int dep) {
    if(dep==lit) {
        if(!sum) return true;
        else return false;
    }
    register int i,j,x,y,u,v;
    for(i=1;i<=k;++i) if(Map[p[i].x][p[i].y])
    for(j=i+1;j<=k;++j) if(i!=j && Map[p[j].x][p[j].y]) { //枚举路径上的两个相邻的点
        x=p[i].x, y=p[i].y;
        u=p[j].x, v=p[j].y;
        register int p1,p2,dx=x-u,dy=y-v;

        int cnt=0, flag=true;
        for(p1=u,p2=v;flag && inrange(p1,p2);p1+=dx,p2+=dy)
            
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值