poj 2311 Cutting Game (SG)

题意:

有一张W*H的纸片。

每人每次可以横着撕或者竖着撕,先撕出1*1那一方胜。

数据范围:

W and H (2 <= W, H <= 200)

思路:

很好抽象出游戏图的模型,用SG解决。直接看代码。

代码:

int dp[maxn][maxn];

int sg(int w,int h){
    if(dp[w][h]!=-1)
        return dp[w][h];
    bool g[maxn];  mem(g,false);
    for(int i=2;i<=w/2;++i)
        g[sg(i,h)^sg(w-i,h)] = true;
    for(int i=2;i<=h/2;++i)
        g[sg(w,i)^sg(w,h-i)] = true;
    for(int i=0;;++i){
        if(!g[i]) return dp[w][h]=i;
    }
}
int main(){
    mem(dp,-1);
    int w,h;
    while(scanf("%d%d",&w,&h)!=EOF){
        if(sg(w,h))
            puts("WIN");
        else
            puts("LOSE");
    }
}
时间: 2024-11-08 19:16:24

poj 2311 Cutting Game (SG)的相关文章

POJ 3253 Fence Repair (优先队列)

POJ 3253 Fence Repair (优先队列) Farmer John wants to repair a small length of the fence around the pasture. He measures the fence and finds that he needsN (1 ≤ N ≤ 20,000) planks of wood, each having some integer lengthLi (1 ≤ Li ≤ 50,000) units. He the

POJ 3292 Semi-prime H-numbers(数)

Semi-prime H-numbers Description This problem is based on an exercise of David Hilbert, who pedagogically suggested that one study the theory of 4n+1 numbers. Here, we do only a bit of that. An H-number is a positive number which is one more than a m

POJ 3301 Texas Trip (三分)

题目链接 题意 : 给你若干个点,让你找最小的正方形覆盖这所有的点.输出面积. 思路 : 三分枚举正方形两对边的距离,然后求出最大,本题用的是旋转正方形,也可以用旋转点,即点的相对位置不变. 正方形从0度到180度变化的过程中,把所有点覆盖,面积肯定是有一个最小峰值,是一个凸函数.因此可以用三分法解决.这里有一个难点就是已知两个定点的x,y坐标,过这两个点做两条平行线,平行线并与x轴成d度的角,怎么算出两条平行线的距离. d1 = fabs(cos(d)*(yi-yj)-sin(d)*(xi-x

POJ 1699 Best Sequence(DFS)

題目鏈接 題意 : 將幾個片段如圖所示方法縮成一個序列,求出最短這個序列. 思路 : 其實我也不知道怎麼做.....看網上都用了DP.....但是我不會.....這個DP不錯,還有用KMP+状压DP做的 1 //1699 2 #include <iostream> 3 #include <stdio.h> 4 #include <string.h> 5 #include <string> 6 7 using namespace std; 8 9 string

POJ 1160 Post Office (动态规划)

Post Office Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 15412   Accepted: 8351 Description There is a straight highway with villages alongside the highway. The highway is represented as an integer axis, and the position of each villa

poj 3440 Coin Toss(概率)

http://poj.org/problem?id=3440 大致题意:给出一个n*m的格子,每个格子的边长为t,随意抛一枚硬币并保证硬币的圆心在格子里或格子边上,硬币的直径为c,求硬币覆盖格子的个数的概率. 思路:高中的概率题,ms是几何概型.根据分别覆盖1,2,3,4个格子时圆心可分部的面积比上总面积就是答案. #include <stdio.h> #include <iostream> #include <algorithm> #include <set&g

POJ题目Java代码(一)

POJ 1001 Exponentiation import java.math.BigDecimal; import java.util.Scanner; public class Poj1001 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNext()){ BigDecimal bigDecimal = new BigDecimal(sc.next())

POJ 3177 Redundant Paths(Tarjan)

题目链接 题意 : 一个无向连通图,最少添加几条边使其成为一个边连通分量 . 思路 :先用Tarjan缩点,缩点之后的图一定是一棵树,边连通度为1.然后找到所有叶子节点,即度数为1的节点的个数leaf,最后要添加的边的条数就是(leaf+1)/2 : 1 // 3177 2 #include <cstdio> 3 #include <cstring> 4 #include <iostream> 5 #include <algorithm> 6 7 using

POJ 3669 Meteor Shower(流星雨)

POJ 3669 Meteor Shower(流星雨) Time Limit: 1000MS    Memory Limit: 65536K Description 题目描述 Bessie hears that an extraordinary meteor shower is coming; reports say that these meteors will crash into earth and destroy anything they hit. Anxious for her sa