Coderforces-455A】的更多相关文章

Servers time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are n servers in a laboratory, each of them can perform tasks. Each server has a unique id - integer from 1 to n. It is known…
Chloe and pleasant prizes time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a pri…
题目大意:给出m组数据,每组数据包括两个数Li与Ri,分别表示左右袜子的索引(下标),表示这一天要穿的袜子:而我们要使得每天穿的这两只袜子的颜色相同,所以可以改变袜子的颜色,每次只能改变一只袜子的颜色. 问:求改变袜子的最少数目,使得每天穿的两只袜子颜色都相同.(一开始读错题目,理解错了,没有认识到Li与Ri是袜子的编号,卡了好久.) 题解: 1.我的理解是用 "图+dfs",每天成对出现的袜子之间都有边,袜子的编号作为节点:输入完所有的数据后,实际上就构成了若干个连通图.对于每个连通…
题目描述: B. Passwords time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vanya is managed to enter his favourite site Codehorses. Vanya uses n distinct passwords for sites at all, however he can…
题目大意:一个纸牌游戏,52张纸牌排成一列,每张纸牌有面值和花色两种属性.每次操作可以用最后一张纸牌将倒数第二张或者倒数第四张替换,但前提是两张牌的花色或者面值相同.问最终能否只剩一张牌. 题目分析:取当前所剩纸牌张数和最后三张牌作为状态,显然深搜要超时.记忆化搜索即可. 代码如下: # include<iostream> # include<string> # include<cstdio> # include<cstring> # include<…
Boredom 题目链接: http://acm.hust.edu.cn/vjudge/contest/121334#problem/G Description Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequ…
<题目链接> 题目大意:给定一个序列,让你在其中挑选一些数,如果你选了x,那么你能够得到x分,但是该序列中所有等于x-1和x+1的元素将全部消失,问你最多能够得多少分. 解题分析:从小到大枚举选的数的数值,同时用DP进行状态的转移,$dp[i]$表示前 $i$ 的数值中,挑选$i$的最大得分. 所以不难得到dp的转移方程为:$$dp[i]=max(dp[i-1],dp[i-2]+num[i]*i)$$ #include <bits/stdc++.h> using namespace…
题目链接:https://codeforces.com/problemset/problem/455/A 题意: 给出一个 $n$ 个数字的整数序列 $a[1 \sim n]$,每次你可以选择一个 $a[k]$ 将其删除,同时还会删除序列中所有等于 $a[k] + 1$ 和 $a[k] - 1$ 的元素. 每做这样一次操作,你可以获得 $a[k]$ 的分数,求可以得到的最大分数. 题解: 首先,看到 $a[1 \sim n]$ 的取值最大不超过 $1e5$,就应当想到在这个上面做文章. $f[x…
A. Boredom time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a ga…
题意:给定一个手机键盘数字九宫格,然后让你判断某种操作是不是唯一的,也就是说是不是可以通过平移也能实现. 析:我的想法是那就平移一下,看看能实现,就四种平移,上,下,左,右,上是-3,要注意0变成8,如果有数字变成小于等于0了,那么就是不可以,同理,下是+3,8可以变成0,其他的也是这样, 注意左右平移是147,和369,是不能平移,然后就AC了.再简化一下就是如果有123,就不能上移,如果有79就不能下移,如果有147就不能左移,如果有369就不能右移,如果有0就不能下左右移. 代码如下: #…
题意:给定一个手机,然后一共有 n 个app,告诉你每个屏幕最多放 k 个,现在要你运行 m 个app,每次都从第一个屏幕开始滑动,每运行一个,它就和前一个交换位置,第一个就不换了,现在问你要滑动多少次. 析:这个题,没什么算法,就是模拟呗,不过要注意时间,不能TLE,所以我们就得提前把所有的位置都存下来,让查找的时间变成 O(1),否则就会超时,可以用两个数组,也可以用map,一个存编号,一个存位置, 然后运行完后再交换就行了. 代码如下: #include <iostream> #incl…
题意:给定 n 个人,在每一时刻一个人进入地铁的概率是 p,站着不动的概率是 1-p,然后问你 t 时间地铁里有多少人. 析:很明显这是一个期望DP,用d[i][j]表示 i 时刻 j 个人进入地铁的概率,有两种情况,要么第 i-1 时刻已经有 j 个人了,那么就不进,要么第 i-1 时刻只有 j-1个人,就得进入, 也就是d[i][j] = d[i-1][j] * (1-P) + d[i-1][j-1] * p;这就是状态转移方程,最重要的是有一种情况一定要注意...那就是当第 i-1 时刻已…
题意:给定 n 个硬币和一个值 k,问你在用一些硬币组成面值为 k的这些硬币还能组成多少种其他面值. 析:如果这样说,由这些硬币能组成多少种不同的面值,那么是不是就很熟悉了,这不就是01背包么,这个题又加了一个限制条件,是用能组成 k 的这些硬币,也是类似的,d[i][j],表示硬币 j 能组成面值 i, 那么如果再加一个硬币x,d[i+x][j]也是可以的,d[i+x][j+x]也是可以的,所以如果d[i][j]成立,那么d[i+x][j],和d[i+x][j+x]也是成立的. 代码如下: #…
D. Sum of Medians time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output In one well-known algorithm of finding the k-th order statistics we should divide all elements into groups of five consecu…
题目链接:点击打开链接 给定一个n长的序列 删除x这个数就能获得x * x的个数 的分数,然后x+1和x-1这2个数会消失.即无法获得这2个数的分数 问最高得分. 先统计每一个数出现的次数.然后dp一下,对于每一个数仅仅有取或不取2种状态. #include <algorithm> #include <cctype> #include <cassert> #include <cstdio> #include <cstring> #include…
A. Boredom time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a ga…
http://codeforces.com/problemset/problem/633/D D. Fibonacci-ish   Yash has recently learnt about the Fibonacci sequence and is very excited about it. He calls a sequence Fibonacci-ish if the sequence consists of at least two elements f0 and f1 are ar…
E. e-Government time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output The best programmers of Embezzland compete to develop a part of the project called "e-Government" — the system of automa…
A. Best Subsegment time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given array a1,a2,…,ana1,a2,…,an. Find the subsegment al,al+1,…,aral,al+1,…,ar (1≤l≤r≤n1≤l≤r≤n) with maximum arith…
A. The Fair Nut and Elevator time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output The Fair Nut lives in nn story house. aiai people live on the ii-th floor of the house. Every person uses elevat…
ProblemA Minimizing the String 题目链接 题解:这一题读完题就写了吧.就是让你删除一个字母,使得剩下的字符组成的字符串的字典序最小:我们只要第一个当前位置的字符比下一个字符小的位置把该字符删去即可: 参考代码: #include<bits/stdc++.h> using namespace std; #define PI acos(-1.0) #define RI register int #define clr(a,b) memset(a,b,sizeof a)…
Portal:http://codeforces.com/problemset/problem/327/D 一座红塔200人,一座蓝塔100人,只有与蓝塔相邻才可以建红塔. '.'处可建塔 '#'处不可建塔 可以随便毁塔 在建造能够容纳最多人数的塔集合情况下,输出对塔的操作(SPJ) 这是一道水题 这是一道卡输入输出的题 DFS就好,反正就是在联通分量里炸割顶留根 #include<iostream> #include<algorithm> #include<set>…
Portal: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1345  http://codeforces.com/gym/100803/attachments  A题 好题! 坑不多,切入比较难 一开始的想法是暴力,由于求得是最小解且此图太大无边界,所以不能DFS,首先想到BFS 解法1 BFS+STL queue #include<iostream> #include<algorithm> #include&…
因为太弱,蒟蒻我从来没有上过div1(这就是今年的最后愿望啊啊啊啊啊)已达成................打cf几乎每次都是fst...........所以我的cf成绩图出现了惊人了正弦函数图像............. 所以现在刷div1的abc(估计只能a和b?)..............学习各位神犇直接简略题解吧............... upd:14.12.31日成功紫名233-- [494A]裸构造...每个#取1最后一个取完即可... [494B]裸DP...以b的下标设状态…
前言 现在全球最大的编程比赛记分网站非CodeForces和AtCoder莫属了,@ezoixx130大佬已经在去年介绍过CodeForces了(传送门),那么现在我们主要谈一下AtCoder. 简介 AtCoder是日本最大的算法竞技网站,正式创立于2012年6月20日,由AtCoder Inc.运行并维护,其域名为https://atcoder.jp/.提供编程在线比赛.过往比赛提交.在线评测等服务. 使用 首页 1.顶部菜单栏功能: 名称 功能 Logo图标及Home 返回首页 Conte…
目录: 1.1093D. Beautiful Graph(DFS染色) 2.514C - Watto and Mechanism(Tire) 3.69E.Subsegments(STL) 4.25C. Roads in Berland(最短路松弛操作) 5.128B. String Problem (floyd预处理) 6.33C.Wonderful Randomized Sum(思维) 7.1292B.Aroma's Search (暴力+思维) 8.1286 A.Garland(DP) 9.…
HDU1176 中文题意不多解释了. 建一个二维dp数组,dp[ i ][ j ]表示第 i 秒落在 j 处一个馅饼.我们需要倒着DP,为什么呢,从 0秒,x=5处出发,假如沿数组正着往下走,终点到哪里我们是不知道的,沿这个路线能最大值,下一秒就未必是最大值.但是我们知道起点,所以我们从终点开始走,走到dp[ 0 ][ 5 ]为止.由于这个总路线存在着诸多未知情况,但是有一点我们可以确定: i , j i+1,j-1       i+1,j       i+1,j+1 对于dp[ i ][ j…