UVA11134_Fabled Rooks】的更多相关文章

大概题意: 在n*n的棋盘上面放n个车,能否使他们互相不攻击(即不能在同一行一列),并且第i个车必须落在第i的矩形范围(xl,yl, xr,yr)之内 xy互相并不干扰,所以就可以把这个二维问题压缩成一维的,即在x轴能否让第i个点落在第i个区间内,如果x或y轴不存在这样放法,那么二维肯定也不可以!!! 当我们转换成一维问题之后,便是一个很经典的区间贪心模型了 贪心策略就是,区间右界越小优先级越高,相同条件下左界越大优先级越高 把这些区间排序之后,如何选取才能保证最优??? 其实这一类大题,贪心策…
UVA - 11134 Fabled Rooks We would like to place n rooks, 1 ≤ n ≤ 5000, on a n × n board subject to the following restrictions The i-th rook can only be placed within the rectan- gle given by its left-upper corner (xli,yli) and its right- lower corner…
http://www.lightoj.com/volume_showproblem.php?problem=1005        PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: 32 MB A rook is a piece used in the game of chess which is played on a board of square grids. A rook can only move…
问题来源:刘汝佳<算法竞赛入门经典--训练指南> P81: 问题描述:你的任务是在n*n(1<=n<=5000)的棋盘上放n辆车,使得任意两辆车不相互攻击,且第i辆车在一个给定的矩形R之内. 问题分析:1.题中最关键的一点是每辆车的x坐标和y坐标可以分开考虑(他们互不影响),不然会变得很复杂,则题目变成两次区间选点问题:使得每辆车在给定的范围内选一个点,任何两辆车不能选同一个点.  2.本题另外一个关键点是贪心法的选择,贪心方法:对所有点的区间,按右端点从小到大排序:每次在一个区间…
We would like to place n rooks, 1 n 5000, on a n nboard subject to the following restrictions• The i-th rook can only be placed within the rectan-gle given by its left-upper corner (xli; yli) and its right-lower corner (xri; yri), where 1 i n, 1 xli…
Problem F: Fabled Rooks We would like to place n rooks, 1 ≤ n ≤ 5000, on a n×n board subject to the following restrictions The i-th rook can only be placed within the rectangle given by its left-upper corner (xli, yli) and its right-lower corner (xri…
We would like to place  n  rooks, 1 ≤  n  ≤ 5000, on a  n×n  board subject to the following restrictions The i-th rook can only be placed within the rectangle given by its left-upper corner (xli, yli) and its right-lower corner (xri, yri), where 1 ≤ …
Problem F: Fabled Rooks We would like to place n rooks, 1 ≤ n ≤ 5000, on a n×n board subject to the following restrictions The i-th rook can only be placed within the rectangle given by its left-upper corner (xli, yli) and its right-lower corner (xri…
题目链接:uva 11134 - Fabled Rooks 题目大意:给出n,表示要在n*n的矩阵上放置n个车,并且保证第i辆车在第i个区间上,每个区间给出左上角和右小角的坐标.另要求任意两个车之间不能互相攻击. 解题思路:因为要保证说每两个车之间不能互相攻击,那么即任意行列都不能摆放两个以上的车,转而言之可以看成是将每一行或列分配给每辆车.如果行和列和起来考虑的话复杂度太高了,但是行和列的分配又互相不影响,所以可以分开讨论. 即对于一个区间[xl,xr],要分配一个x给它,做法和uva 142…
1005 - Rooks   PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: 32 MB A rook is a piece used in the game of chess which is played on a board of square grids. A rook can only move vertically or horizontally from its current positio…
Attacking rooks Time Limit: 20000ms, Special Time Limit:50000ms, Memory Limit:65536KB Total submit users: 12, Accepted users: 7 Problem 13028 : No special judgement Problem description Chess inspired problems are a common source of exercises in algor…
Super Rooks on Chessboard UVA - 12633 题意: 超级车可以攻击行.列.主对角线3 个方向. R * C 的棋盘上有N 个超级车,问不被攻击的格子总数. 行列好好做啊,就是不被攻击的行数*列数 减去主对角线的,就是不被攻击的行列中求\(r - c = d\)的三元组个数 考虑写出行和列生成函数 \(A(x)=\sum x^{r_i},B(x)=\sum x^{-c_i}\),乘起来就行了 可以乘上\(x^c\)来避免负指数 #include <iostream>…
Problem UVA11134-Fabled Rooks Accept: 716  Submit: 6134Time Limit: 3000mSec Problem Description We would like to place n rooks, 1 ≤ n ≤ 5000, on a n × n board subject to the following restrictions• The i-th rook can only be placed within the rectangl…
E. Rooks and Rectangles Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/524/E Description Polycarpus has a chessboard of size n × m, where k rooks are placed. Polycarpus hasn't yet invented the rules of the game…
这道题非常好,不仅用到了把复杂问题分解为若干个熟悉的简单问题的方法,更是考察了对贪心法的理解和运用是否到位. 首先,如果直接在二维的棋盘上考虑怎么放不好弄,那么注意到x和y无关(因为两个车完全可以在同一条斜线上,这点和皇后问题不一样),那么就可以分别考虑两个一维的问题:这是一种区间选点问题,在每个区间里都只选一个点,最后这些点分别是1到n.这就联想到这样一个经典的贪心法解决的区间选点问题:数轴上有n个闭区间[ai,bi],选取尽量少的点,使得每个区间都至少含有一个点.这个问题的解决方法就是把所有…
版权声明:本文作者靖心.靖空间地址:http://blog.csdn.net/kenden23/,未经本作者同意不得转载. https://blog.csdn.net/kenden23/article/details/31760795 A rook is a piece used in the game of chess which is played on a board of square grids. A rook can only move vertically or horizonta…
A rook is a piece used in the game of chess which is played on a board of square grids. A rook can only move vertically or horizontally from its current position and two rooks attack each other if one is on the path of the other. In the following fig…
We would like to place n rooks, ≤ n ≤ , on a n × n board subject to the following restrictions • The i-th rook can only be placed within the rectangle given by its left-upper corner (xli, yli) and its rightlower corner (xri, yri), ≤ i ≤ n, ≤ yli ≤ yr…
LINK:Placing Rooks 丢人现场.jpg 没看到题目中的条件 放n个rook 我以为可以无限放 自闭了好半天. 其实只用放n个.那么就容易很多了. 可以发现 不管怎么放 所有列/所有行 都必须得放有. 那么最多只有n-1个pairs 当k==0时 容易发现是一个n!. 总之还是迷了很久.一道比较锻炼我当前水平的计数题. 有k行空着 比较显然 因为一旦多加一对 那么两个棋子就会放在同一行. 考虑计算出方案数 容易发现一开始的方案数为 \(C(n,k)\cdot (n-k)^n\)必然…
CF1465-C. Peaceful Rooks 预备小知识: Rook(国际象棋中的车). 国际象棋中的棋子.每人有2个,他只能直走,不能斜走,除王车易位外不能越子. -- 来自<百度百科> 题意: 题目给出一个\(n\times n\)的棋盘,棋盘中有\(m(m<n)\)个车.最一开始任意两个车都不能打到对方(即都不在同一行或同一列). 每一个回合你可以让一个车水平或垂直移动任意距离,但是要求车移动后不能让其他车可以打到它.现在问你至少多少回合之后,所有车能够都移动到主对角线上. 思…
题目 Source http://acm.hust.edu.cn/vjudge/problem/42145 Description Let’s assume there is a new chess piece named Super-rook. When placed at a cell of a chessboard, it attacks all the cells that belong to the same row or same column. Additionally it at…
普通的贪心题. 虽然图是二维的,但可以把横向和纵向分开处理. 将区间按右端点排序,然后从区间左端点到右端点找第一个空位置放棋子即可. /*by SilverN*/ #include<algorithm> #include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<vector> using namespace std; ; int rea…
题目是在n*n的棋盘上放k个车使其不互相攻击的方案数. 首先可以明确的是n*n最多只能合法地放n个车,即每一行都指派一个列去放车. dp[i][j]表示棋盘前i行总共放了j个车的方案数 dp[0][0]=1 转移就是从第i-1行转移到第i行,对于第i行要嘛放上一个车要嘛不放,放的话有n-j-1种方法.即dp[i][j]=dp[i-1][j]+dp[i-1][j-1]*(n-j-1). #include<cstdio> #include<cstring> using namespac…
Please note: VROOK cannot go back-ward - that leads to a simple variation to Game of Nim: just XOR. t = int(input()) for _ in range(t): n = int(input()) # Get input p1 = [] for _ in range(n): p1.append(int(input())) p2 = [] for _ in range(n): p2.appe…
这道题真是WA得我心力交瘁,好讨厌的感觉啊! 简直木有写题解的心情了 题意: n×n的棋盘里,放置n个车,使得任意两车不同行且不同列,且第i个车必须放在给定的第i个矩形范围内.输出一种方案,即每个车的坐标,无解的话则输出“IMPOSSIBLE” 行和列是独立的,所以可以分开处理,将二维的转化成了一维区间上的取点问题: 有一个长度为n的区间,还有n个小区间,求一种方案,在每个小区间的范围取一个点,是的大区间上每个单位1的区间里都有点. 开始写的贪心是错误的: 按区间的左端点从小到大排序,然后右端点…
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1005 纸上画一下,找了一下规律,Ank*Cnk. //#pragma comment(linker, "/STACK:102400000, 102400000") #include <algorithm> #include <iostream> #include <cstdlib> #include <cstring>…
题意:给出一个n行的棋盘,每行的长度任意,问在该棋盘中放k个车(不能同行或者同列)有多少种放法(n <= 250, 每行的长度 <= 250). 题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=269 ——>>开始的时候冒险用dfs去做,结果TLE了...改dp,大数长度开小点WA,开大点MLE……最后改用滚动数组开1000位的大数长度才A掉…… 设d[i][j]表示前i行放j个车的方法数, 则状态转移方程为:d[i…
题意: 给n(<=250)条水平网格,然后在上面放k棋子,每行每列都只能放一个.求方法总数. Solution: 简单的DP, 只要对给出的水平长度排个序就很容易处理了. 需要用到高精度. 偷懒用java写了 import java.util.*; import java.math.*; public class Solution { public static void main(String[] args){ Scanner cin=new Scanner(System.in); int n…
题意: 求在n*n(n<10)的棋盘上放k个车(水平竖直行走)的方案数. Solution SGU220的简化版.直接DP 显然当k>n时,ans=0; f[i][j]代表在前n行放了j个棋子. 转移方程 f[i][j]=f[i-1][j]+f[i-1][j-1]*(n-j+1); #include <iostream> using namespace std; ][], n, m, ans; int main() { ios::sync_with_stdio (); cin &g…
题目大意: 给你一个N和K要求确定有多少种放法,使得没有两个车在一条线上. N*N的矩阵, 有K个棋子. 题目分析: 我是用DP来写的,关于子结构的考虑是这样的. 假设第n*n的矩阵放k个棋子那么,这个推导过程如下.   当我们们第n*n的矩阵的时候可以考虑第(n-1)*(n-1)的矩阵经过哪些变换可以变成n*n的. 如上图蓝色方格.我们加入蓝色方格之后,矩阵就会增大一圈. 1.加入我们蓝色方格不放置棋子. dp[n-1][k] 2.加入蓝色方格放置一枚棋子,那么我们其实有三种位置可以放置:(1…