1562: Fun House】的更多相关文章

题目传送门 /* 题意:光线从 '*' 发射,遇到 '/' 或 '\' 进行反射,最后射到墙上,将 'x' 变成 '&' 模拟:仔细读题,搞清楚要做什么,就是i,j的移动,直到撞到墙,模拟一下一次AC,不要被题目吓怕了:) */ #include <cstdio> #include <iostream> #include <algorithm> #include <stack> #include <cmath> #include <…
题目链接 题意 : 问一个m×n的矩形中,有多少个pocket,如果两块油田相连(上下左右或者对角连着也算),就算一个pocket . 思路 : 写好8个方向搜就可以了,每次找的时候可以先把那个点直接变为*,这样可以避免重复搜索. //POJ 1562 ZOJ 1709 #include <stdio.h> #include <string.h> #include <iostream> #include <stack> #include <algori…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1562 Problem Description Happy new year to everybody!Now, I want you to guess a minimum number x betwwn 1000 and 9999 to let (1) x % a = 0;(2) (x+1) % b = 0;(3) (x+2) % c = 0;and a, b, c are integers be…
http://poj.org/problem?id=1562 #include<iostream> using namespace std; ,m=,sum=; ][]; ][]={-,, ,, ,-, ,, ,, -,-, -,, ,- }; void dfs(int a,int b) { if(!aa[a][b])return; aa[a][b]=; ;i<;i++) { ]; ]; &&a1<m&&b1>=&&b1<…
题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=1562 题目大意: 思路: 逆序匹配,加边匹配的时候保持字典序小的先加入. 具体证明:https://www.byvoid.com/zhs/blog/noi-2009-transform #include<bits/stdc++.h> #define IOS ios::sync_with_stdio(false);//不可再使用scanf printf #define Max(a,…
Link: BZOJ 1562 传送门 Solution: 一道比较考对$Hungry$算法理解的题目 首先可以轻松看出原序列和答案序列的对应关系,从而建出二分图匹配模型 下面的关键在于如何保证字典序最小 第一种方式是暴力逐位确定: 对于$1....n$每一位都先贪心选取字典序小的节点,判断将该边除去后能否完全匹配,不能再修改 但这样复杂度明显是$O(n^3)$ 第二种方式是逆向匹配: 其实就是暴力贪心的思想,但逆序匹配后就不用判断了,省去了每次重复的判断: 从后往前对于每个点先选择字典序小的节…
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1562 题意: 给定n,定义D(x,y) =  min(|x-y|, n-|x-y|),然后给定数组d[i] = D(i,T[i]). 让你求一个0到n-1的排列T,下标i∈[0,n-1],满足给定的D(i,T[i]),且字典序最小. 若没有答案输出"No Answer". 题解: 其实就是让你求一个排列T,其中T[i]要么填(i+d[i])%n,要么填(i-d[i]+n)%n.…
  1562 玻璃切割 http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1562 题目来源: CodeForces 基准时间限制:1.5 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 现在有一块玻璃,是长方形的(w 毫米× h 毫米),现在要对他进行切割. 切割的方向有两种,横向和纵向.每一次切割之后就会有若干块玻璃被分成两块更小的玻璃.在切割之后玻璃不会被移动. 现在想知道每次切割之后面积最大的一块…
1562 玻璃切割 题目来源: CodeForces 基准时间限制:1.5 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 现在有一块玻璃,是长方形的(w 毫米× h 毫米),现在要对他进行切割. 切割的方向有两种,横向和纵向.每一次切割之后就会有若干块玻璃被分成两块更小的玻璃.在切割之后玻璃不会被移动. 现在想知道每次切割之后面积最大的一块玻璃是多少. 样例解释: 对于第四次切割,下面四块玻璃的面积是一样大的.都是2. Input 单组测试数据. 第一行有三个整数 w,h,n…
现在,又可以和她没心没肺的开着玩笑,感觉真好. 思念,是一种后知后觉的痛. 她说,今后做好朋友吧,说这句话的时候都没感觉.. 我想我该恨我自己,肆无忌惮的把她带进我的梦,当成了梦的主角. 梦醒之后总是无边的疼痛,无比的失落. 我果然还是不死心. 我为什么非得离开你,在夜的利刃上劈伤自己? 早上考完数逻,考试太水.好吧期中考.T T 来水一发,准备去做数据结构作业,种树呀种树...两颗啊两颗... ---------------------------------------------准备种树的…
这道题主要注意输入的问题,以及对周围搜索时的注意,要使用递归,多次调用,附上一组数据 11 20*@*@*@@@**@*@**@@@*****@*@*@*@*@****@**@*@*@*@*@*@*@********@*************@@**@*@*@*@*@*@************@*@*@*@*@*@*@*@**************@*@*@***********@*@*@*@*@*@*****@*@**************************@*@*@*@***@…
Description Input Output Sample Input 5 1 1 2 2 1 Sample Output 1 2 4 0 3 HINT 30%的数据中N≤50:60%的数据中N≤500:100%的数据中N≤10000. 二分图匹配,倒着匹配,每次选小的增广(随便乱yy一下,应该就可以证明是字典序最小的吧) const maxn=; var first,link:..maxn]of longint; a:..maxn,..]of longint; next,last:..ma…
题目 简单的题目,只是测试案例的输入后面可能有空格,所以要注意一下输入方式. #define _CRT_SECURE_NO_WARNINGS //题目的案例输入n,m后面有些貌似有空格... #include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> #include<queue> using namespace std; #define MAXN 110 /…
题目: http://cojs.tk/cogs/problem/problem.php?pid=409 409. [NOI2009]变换序列 ★★☆   输入文件:transform.in   输出文件:transform.out   简单对比时间限制:1 s   内存限制:128 MB [问题描述]        对于N个整数0, 1, ……, N-1,一个变换序列T可以将i变成Ti,其中 定义x和y之间的距离.给定每个i和Ti之间的距离D(i,Ti), 你需要求出一个满足要求的变换序列T.如…
Problem Description Happy new year to everybody! Now, I want you to guess a minimum number x betwwn 1000 and 9999 to let (1) x % a = 0; (2) (x+1) % b = 0; (3) (x+2) % c = 0; and a, b, c are integers between 1 and 100. Given a,b,c, tell me what is the…
Oil Deposits Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14628   Accepted: 7972 Description The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular r…
油田问题(L - 暴力求解.DFS) Description The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a grid that divides the land into numerou…
转载请注明出处:http://blog.csdn.net/a1dark 大规模的图论切题之旅正式开始了.由于今天停了一天的电.所以晚上才开始切题.直到昨晚才把图论大概看了一遍.虽然网络流部分还是不怎么懂.但是也懂得了一些基础的算法.相信只要不断的刷题.必然可以可以搞懂.至于连通和匹配还是只是有那么一些概念.只会一些模板.等做题做多了自然就会懂了.努力切题中... 分析:刚开始水一发.这题很简单.应该尽量1次做对.一个简单的图的DFS搜索.思路就不讲了.看看代码应该没什么问题. #include<…
简单地DFS Oil Deposits Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12801   Accepted: 6998 Description The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectan…
Oil Deposits Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16655   Accepted: 8917 Description The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular r…
Description The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a grid that divides the land into numerous square plots. It…
题目: The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a grid that divides the land into numerous square plots. It then ana…
Description Input Output Sample Input 5 1 1 2 2 1 Sample Output 1 2 4 0 3 HINT 30%的数据中N≤50: 60%的数据中N≤500: 100%的数据中N≤10000. 匈牙利裸题因为要注意字典序所以加边还有find的时候要注意一下先后顺序 #include<iostream> #include<cstdio> #include<cstring> #include<cstdlib>…
显然每个位置只有两个情况,所以用二分图最大匹配来求解. 如果二分图有完全匹配,则有解. 关键是如何求最小的字典序解. 实际上用匈牙利算法从后面开始找增广路,并优先匹配字典序小的即可. # include <cstdio> # include <cstring> # include <cstdlib> # include <iostream> # include <vector> # include <queue> # include…
反素数的定义:对于不论什么正整数,其约数个数记为.比如,假设某个正整数满足:对随意的正整 数.都有,那么称为反素数. 从反素数的定义中能够看出两个性质: (1)一个反素数的全部质因子必定是从2開始的连续若干个质数.由于反素数是保证约数个数为的这个数尽量小 (2)相同的道理,假设,那么必有 个人理解性证明: 对(1)如果不是从2開始,那么如果n的最小素因素是k,把k换成2,2的次数仍等于k的次数,得到N,可知,N<n,而且f(n)==f(N).与n是反素数矛盾 对(2)如果ti<tj   ti,…
[NOI2009] 变换序列 [题解] 就是有一个序列,每个位置可以填两个数,不可重复,问最小字典序. 显然,可以建一个二分图,判合法就是找完美匹配. 那怎么弄最小字典序呢?有好多种解法,我这里给出了两种. 解法一: 先求出它的一个完美匹配,把每个点扫一遍,如果它连的点是它能连的最小的了,就不管他,否则强制将当前节点与其能连的最小点对应,这时从这个点找增广路,如果有,就算修正成功,否则修正失败. 这个方法的好处是通用,时间复杂度O(n*n) 解法二: 从最后一个点开始求增广路,求增广路时优先考虑…
玻璃切割 思路: 并查集: 离线操作: 先把每次切割都存下来: 然后从后面不断合并切割: 然后每次更新最大长和宽: 记录答案: 要开longlong: 来,上代码 #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define maxn 400005 #define ll long long struct Op…
Oil Deposits The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a grid that divides the land into numerous square plots. It…
#include<stdio.h> #include<iostream> #include<set> using namespace std; typedef long long LL; ; LL ans[maxn]; int x[maxn]; char c[maxn]; set<int> row,col; set<int>:: iterator it; int main() { int w, h, n, maxr, maxc; while(~s…