Attack on Titan(状态压缩)

Attack on Titan

WL大神最近迷上了一款名叫《神话时代》的游戏,这个游戏里有一种非常强力的兵种——泰坦,可以不费吹灰之力地摧毁一座座村庄。但是,泰坦有一个弱点,就是不能过河。有一次,WL大神玩了一个布满河流的地图,这个地图上坐落着N个村庄,M条河流(每条河流都可以视作一条横跨地图的直线)。WL大神一口气使用“TITANOMACHY”秘籍在一些地点共召唤了K个泰坦。现在,WL大神想知道都有哪些村庄可以被摧毁。

Input

输入数据有多组。

第一行输入一个整数T(T≤10),表示数据组数。

每组数据第一行为三个整数N(N≤50000)、K(K≤50000)、M(M≤50),分别代表村庄数、泰坦数、河流数。

接下来N行每行两个整数x、y(0≤x,y≤10^6),代表第i个村庄的坐标。

接下来K行每行两个整数x、y(0≤x,y≤10^6),代表第i个泰坦的坐标。

接下来M行每行四个整数x1、y1、x2、y2(0≤x1,y1,x2,y2≤10^6),代表第i条河流流经的两个点,保证(x1,y1)与(x2,y2)不重合,保证村庄和泰坦不会在任何一条河流上。

Output

每组数据输出N行,如果第i个村庄可以被摧毁则在第i行输出1,否则输出0。

Sample Input

1
2 1 1
0 0
2 0
2 2
1 0 1 1

Sample Output

0
1

Source

第十三届北京师范大学程序设计竞赛决赛

Author

hwq

记录每个泰坦相对每条河流的位置,然后在来判断每个村庄相对河流的位置,用状态压缩存;这里特别注意的是,用map<string,bool>,一开始,我们用map<long long,bool>,结果就WA了。。。T^T .今天好忧桑,各种WA。。。

转载请注明出处:http://blog.csdn.net/u010579068/article/details/45606905

题目链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=49099

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;
#define ls 2*i
#define rs 2*i+1
#define up(i,x,y) for(i=x;i<=y;i++)
#define down(i,x,y) for(i=x;i>=y;i--)
#define mem(a,x) memset(a,x,sizeof(a))
#define w(a) while(a)
#define LL long long
const double pi = acos(-1.0);
#define N 50005
#define mod 19999997
const int INF = 0x3f3f3f3f;
#define exp 1e-8

struct Point
{
    LL x,y;
    Point(LL x=0,LL y=0):x(x),y(y) {} //构造函数,方便代码编写

};

typedef Point Vector;//Vector只是Point的别名

//向量+向量=向量;    向量+点=点
Vector operator + (Vector A,Vector B)
{
    return Vector(A.x+B.x,A.y+B.y);
}

//点-点=向量
inline Vector operator - (Point A,Point B)
{
    return Vector(A.x-B.x,A.y-B.y);
}

inline bool Cross(Vector A,Vector B)
{
    return A.x*B.y>B.x*A.y?true:false;
}
inline bool judge(Point A,Point B,Point C)
{
    return Cross(B-A,C-A);
}

map<string,bool> vis;
Point a[N],b[N],c[55][2];

int main()
{
    LL t,i,j;
    LL n,m,k;
    scanf("%lld",&t);
    w(t--)
    {
        vis.clear();
        scanf("%lld%lld%lld",&n,&m,&k);
        up(i,0,n-1)
        {
            scanf("%lld%lld",&a[i].x,&a[i].y);
        }
        up(i,0,m-1)
        {
            scanf("%lld%lld",&b[i].x,&b[i].y);
        }
        up(i,0,k-1)
        {
            scanf("%lld%lld%lld%lld",&c[i][0].x,&c[i][0].y,&c[i][1].x,&c[i][1].y);
        }
        up(i,0,m-1)
        {
            string s = "";
            up(j,0,k-1)
            {
                if(judge(c[j][0],c[j][1],b[i]))
                    s+="1";
                else
                    s+="0";
            }
            s+="";
           // printf("s1= %lld\n",s);
            vis[s] = true;
        }
        up(i,0,n-1)
        {
            string s = "";
            up(j,0,k-1)
            {
                if(judge(c[j][0],c[j][1],a[i]))
                    s+="1";
                else
                    s+="0";
            }
            s+="";
       //     printf("s2= %lld\n",s);
            if(vis[s]==true)
                printf("1\n");
            else
                printf("0\n");
        }
    }

    return 0;
}
时间: 2024-07-29 21:13:55

Attack on Titan(状态压缩)的相关文章

uva 11195 Another queen (用状态压缩解决N后问题)

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2136 Problem A Another n-Queen Problem I guess the n-queen problem is known by every person who has studied backtracking. In this problem you s

HDU3920:Clear All of Them I(状态压缩)

Problem Description Acmers have been the Earth Protector against the evil enemy for a long time, now it's your turn to protect our home. There are 2 * n enemies in the map. Your task is to clear all of them with your super laser gun at the fixed posi

uva 11825 Hackers&#39; Crackdown(状态压缩DP)

Hackers' Crackdown Input: Standard Input Output: Standard Output   Miracle Corporations has a number of system services running in a distributed computer system which is a prime target for hackers. The system is basically a set of N computer nodes wi

UVa11795 Mega Man&#39;s Mission(状态压缩DP)

Mega Man's Mission Mega Man is off to save theworld again. His objective is to kill the Robots created by Dr.Wily whose motive is to conquer the world. In each mission, he willtry to destroy a particular Robot. Initially, Mega Man is equippedwith a w

胜利大逃亡(续)(状态压缩bfs)

胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7357    Accepted Submission(s): 2552 Problem Description Ignatius再次被魔王抓走了(搞不懂他咋这么讨魔王喜欢)……这次魔王汲取了上次的教训,把Ignatius关在一个n*m的地牢里,并在地牢的某些地方安装了带

uva 818(dfs+图+状态压缩)

题意:有n个环,编号从1到n,给出了一些环环相扣的情况,比如给a和b表示a和b两个环的扣在一起的,每个环都是可以打开的,问最少打开多少个环,然后再扣好,可以让所有的环成为一条链. 题解:状态压缩把所有的打开环的情况枚举出来,然后拿去判断是否成立,更新打开环后的图g[i][j],和每个点的度数,不成立有三种情况,1.计算没有打开的环的度数,如果大于2说明不会有链,2.把没有打开环拿去dfs,访问过就vis[i]++,如果vis[i]>=2说明存在环,3.如果打开的环数num + 1小于链的数量,说

POJ 3254 Corn Fields 状态压缩DP (C++/Java)

http://poj.org/problem?id=3254 题目大意: 一个农民有n行m列的地方,每个格子用1代表可以种草地,而0不可以.放牛只能在有草地的,但是相邻的草地不能同时放牛, 问总共有多少种方法. 思路: 状态压缩的DP. 可以用二进制数字来表示放牧情况并判断该状态是否满足条件. 这题的限制条件有两个: 1.草地限制. 2.相邻限制. 对于草地限制,因为输入的时候1是可以种草地的. 以"11110"草地分析,就只有最后一个是不可以种草的.取反后得00001  .(为啥取反

dp状态压缩

dp状态压缩 动态规划本来就很抽象,状态的设定和状态的转移都不好把握,而状态压缩的动态规划解决的就是那种状态很多,不容易用一般的方法表示的动态规划问题,这个就更加的难于把握了.难点在于以下几个方面:状态怎么压缩?压缩后怎么表示?怎么转移?是否具有最优子结构?是否满足后效性?涉及到一些位运算的操作,虽然比较抽象,但本质还是动态规划.找准动态规划几个方面的问题,深刻理解动态规划的原理,开动脑筋思考问题.这才是掌握动态规划的关键. 动态规划最关键的要处理的问题就是位运算的操作,容易出错,状态的设计也直

HDU3001(KB2-J 状态压缩dp)

Travelling Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 8103    Accepted Submission(s): 2642 Problem Description After coding so many days,Mr Acmer wants to have a good rest.So travelling is