UVALive 4255 Guess】的更多相关文章

算好题目,反正我没想到可以用图论做(虽然现在做的是图论专题= =) 首先是要把求每个位置上的值转化为求 “前缀和之差”,这是一个很有用的技巧 其次,由输入的(n+(n-1)+...+2+1)个符号,可以确定出 n个前缀和的大小关系,并从大到小做有向边建图 之后,用拓扑排序依次从大到小找到前缀和,与此同时对num[]做处理,实际上是离散出这n个值. 这n值符合之前的大小关系,所以他们两两相减,就得到了题目要求的值 #include<stdio.h> #include<string.h>…
这题竟然是图论···orz 题意:给出一个整数序列a1,a2,--,可以得到如下矩阵 1 2 3 4 1 - + 0 + 2   + + + 3       -  - 4         + "-"表示从ai到aj的和是负数,"+"表示和是正数,"0"表示和是0.现给出矩阵,求序列,每个整数的绝对值不超过10. 解法:转化为前缀和问题,矩阵可以表示前缀和的关系,用b表示前缀和,例如"-"表示b[j]-b[i-1]<0,即…
题目链接:https://cn.vjudge.net/contest/209473#problem/B 题目大意:对于n个数字,给出sum[j]-sum[i](sum表示前缀和)的符号(正负零),求一组n个数的的可行解(n个数都在-10——10之间)[保证一定有解] 解题思路: 第一反应!差分约束! 差分约束是用来求解不等式组的合理解的,用在此题上刚好,把sum[i]-sum[j]>0转化为sum[i]-sum[j]>=-1,小于零同理.把sum[i]-sum[j]==0转化为sum[i]-s…
Guess 题目传送:Guess 白书例题 注意拓扑排序时,,入度同一时候为0的前缀和须要赋值为同一个数(这个数能够随机取.由于前缀和是累加的,每个a的数值都仅仅和前缀和之差有关).,由于此时能够看成他们的前缀和是相等的,不存在大小关系,,而存在大小关系的都连了一条有向边. .假设此时不赋值为同一个数,,可能对于符号0不是正解.,从而产生错误的结果.. AC代码: #include <map> #include <set> #include <list> #includ…
Given a sequence of integers, a1, a2, . . . , an, we define its sign matrix S such that, for 1 ≤ i ≤ j ≤ n, Sij = “ + ” if ai + . . . + aj > 0; Sij = “ − ” if ai + . . . + aj < 0; and Sij = “0” otherwise. For example, if (a1, a2, a3, a4) = (−1, 5, −…
UVALive - 4108 SKYLINE Time Limit: 3000MS     64bit IO Format: %lld & %llu Submit Status uDebug Description   The skyline of Singapore as viewed from the Marina Promenade (shown on the left) is one of the iconic scenes of Singapore. Country X would a…
UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device with a variable electric resistance. It has two terminals and some kind of control mechanism (often a dial, a wheel or a slide) with which the resistance…
UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here comes a problem about words. Know- ing that Ray has a photographic memory and this may not trouble him, Neal gives it to Jiejie. Since Jiejie can’t remem…
题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000即为距离: 详细解释:http://www.cnblogs.com/zywscq/p/4268556.html */ #include <cstdio> #include <iostream> #include <algorithm> #include <cmath&…
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4156 题目拷贝难度大我就不复制了. 题目大意:维护一个字符串,要求支持插入.删除操作,还有输出第 i 次操作后的某个子串.强制在线. 思路1:使用可持久化treap可破,详细可见CLJ的<可持久化数据结构的研究>. 思路2:rope大法好,详见:http…