CodeForces 688C-NP-Hard Problem】的更多相关文章

Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting. Suppose the graph G is given. Subset A of its vertices is called a vertex cover of this graph, if for each edge uv ther…
题目链接: C. NP-Hard Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem ve…
[codeforces 528]B. Clique Problem 试题描述 The clique problem is one of the most well-known NP-complete problems. Under some simplification it can be formulated as follows. Consider an undirected graph G. It is required to find a subset of vertices C of…
http://codeforces.com/contest/325/problem/B B. Stadium and Games time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Daniel is organizing a football tournament. He has come up with the followin…
题目链接:Codeforces 442B Andrey and Problem 题目大意:Andrey有一个问题,想要朋友们为自己出一道题,如今他有n个朋友.每一个朋友想出题目的概率为pi,可是他能够同一时候向多个人寻求帮助.只是他仅仅能要一道题,也就是假设他向两个人寻求帮助,假设两个人都成功出题,也是不能够的. 解题思路:贪心,从概率最大的人開始考虑.假设询问他使得概率变大,则要询问. #include <cstdio> #include <cstring> #include &…
B. Save the problem! http://codeforces.com/contest/867/problem/B time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Attention: we lost all the test cases for this problem, so instead of solvi…
题目链接:http://codeforces.com/contest/776/problem/D 把每一个钥匙拆成两个点${x,x+m}$,分别表示选不选这把钥匙. 我们知道一扇门一定对应了两把钥匙. 设一扇门对应的要是分别为$u,v$,${link(x,y)}$表示点$x$向点$y$连边. 如果这扇门要操作一次,那就是两把当中选一把:${link(u,v+m),link(v,u+m)}$.这表示的是如果我选了拿第$u$把钥匙就不能拿第$v$把钥匙,如果我选了拿第$v$把钥匙就不能拿第$u$把钥…
codeforces 803G Periodic RMQ Problem 题意 长度为\(1e5\)的数组复制\(1e4\)次,对新的数组进行区间覆盖和区间最小值查询两种操作,操作次数\(1e5\). 参考博客 http://kugwzk.info/index.php/archives/2404 题解一 小数组复用多次变成大数组,那么可以用ST表维护小数组的区间最小值,大数组还是用线段树维护\(Min[]\)和\(lazy[]\),但是不用进行build操作,所以upd和qry操作中标记下传的时…
[题目链接] https://codeforces.com/contest/986/problem/E [算法] X到Y的路径积 , 可以转化为X到根的路径积乘Y到根的路径积 , 除以LCA到根的路径积 , 再除以LCA父节点到根的路径积 考虑如何计算根到X路径上每个点与Value的GCD之积 不妨对于每个质数P开一个数组cnt[] , 表示根到当前节点P^i有多少个 , 我们可以在DFS的过程中维护这个数组 将询问离线即可 时间复杂度 : O(V + NlogN + QlogV^2) [代码]…
[题目链接]:http://codeforces.com/contest/527/problem/D [题意] 一维线段上有n个点 每个点有坐标和权值两个域分别为xi,wi; 任意一对点(i,j) 如果|xi-xj|>=wi+wj 则在这两个点之间连一条边; 让你求最大团; 团就是任意两个点之间都有边相连; [题解] |xi-xj|>=wi+wj; 这里的绝对值直接去掉好了: 然后可以变形为 xi-wi>=xj+wj (或者是xj-wj>=xi+wi也没差) 总之就是xi-wi如果…
[题目链接]:http://codeforces.com/contest/793/problem/C [题意] 给你每个点x轴移动速度,y轴移动速度; 问你有没有某个时刻,所有的点都"严格"在所给的矩形内 [题解] 把二维的问题转化成一维的问题; 那样问题就转换成 x1..x2是目标的线段(一维的) 然后有若干个xi 问你从xi变化到到x1..x2这个区间最短和最长时间(分别对应第一次进入这个区间和出这个区间的时间); yi同理; 然后求时间的交集就可以了; 对于都刚好在边框上的情况;…
[题目链接]:http://codeforces.com/contest/807/problem/D [题意] 给出n个人的比赛信息; 5道题 每道题,或是没被解决->用-1表示; 或者给出解题的所用的时间; (每道题的分数与解决率有关,越高,分越低); 然后有个人想利用这个特点,注册很多个账号; 试图改变每道题的解决率,以期让自己的分数大于某个人; 如果这个人没有解决某道题的话; 那些新加入的人也不能解决那道题. 问最少需要注册多少个账号才能让你的分数大于某个人; [题解] 顺序枚举加入了多少…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output There is a polyline going through points (0, 0) – (x, x) – (2x, 0) – (3x, x) – (4x, 0) – - - (2kx, 0) – (2kx + x, x) – -. We know that the polyli…
题目链接:http://codeforces.com/contest/713/problem/C 题解:这题也算是挺经典的题目了,这里附上3种解法优化程度层层递进,还有这里a[i]-i<=a[i+1]-(i+1),处理一下. 首先是最基础的dp[i][j]前i位最大值为j的最小值为多少. #include <iostream> #include <cstring> #include <cstdio> #include <cmath> #include…
题目链接:http://codeforces.com/contest/807/problem/D 题意:对于动态计分的 Codeforces Round ,已知每题的 score 是根据 Round 参加人数和该题过题人数计算,两者之比结合上图得出该题的分数.某人在该题的得分为 score*(1−t/250) 其中 t 表示通过该题的时间. 已知参加该场比赛的所有参加者的过题情况(包括 Vasya 和 Petya),问如何通过增加新的参赛者(尽量少),使得 Vasya 的最终得分高于 Petya…
[Codeforces 464E] The Classic Problem(可持久化线段树) 题面 给出一个带权无向图,每条边的边权是\(2^{x_i}(x_i<10^5)\),求s到t的最短路\(\mathrm{mod} \ 10^9+7\)的值 分析 显然边权存不下,由于取模会影响大小关系,不能直接取模然后跑dijkstra 考虑用可持久化线段树维护每个点到起点的距离(二进制表示),即维护一个01序列,[1,n]从低位到高位存储. 修改的时候我们要把第i位+1,如果第i位是0,直接取反就可以…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Bachgold problem is very easy to formulate. Given a positive integer n represent it as a sum of maximum possible number of prime numbers. One can…
题目链接:http://codeforces.com/problemset/problem/706/C 给你n个字符串,可以反转任意一个字符串,反转每个字符串都有其对应的花费ci. 经过操作后是否能满足字符串str[i]>=str[i-1],能就输出最小花费,不能输出-1. dp[i][0] 表示不反转i的最小花费(str[i] >= str[i - 1] || str[i] >= reverse(str[i - 1])) dp[i][1] 则表示反转i的最小花费... 初始dp[1][…
[题目链接] http://codeforces.com/problemset/problem/713/C [题目大意] 给出一个数列,请你经过调整使得其成为严格单调递增的数列,调整就是给某些位置加上或者减去某个数,调整的代价是加上或者减去的数的绝对值之和,请你输出最小代价. [题解] 先考虑这样一个问题,如果是非严格单调递增该如何做,我们会发现每次调整,都是调整某个数字为原先数列中存在的数字,最后才是最优的,所以,我们设DP[i][j]表示前i个数字,最后一个数为原先数列排序后第j大的数字的最…
先上题目: A - Tourist Problem Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 340C Description Iahub is a big fan of tourists. He wants to become a tourist himself, so he planned a trip. The…
http://codeforces.com/problemset/problem/845/G 从顶点1dfs全图,遇到环则增加一种备选方案,环上的环不需要走到前一个环上作为条件,因为走完第二个环可以从第一个环原路返回. 对每种备选方案通过x = min(x,x^v[i]) 保留备选方案中不存在的最高位,如果能由已经存在的备选方案组合得到则结果为零 最后对val[n]做一次类似的操作得到答案 #include<bits/stdc++.h> using namespace std; ; vecto…
B. A Trivial Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer m and asks f…
B. Far Relative’s Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them c…
Problem B. Geometry ProblemTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88926#problem/B Description Peter is studying in the third grade of elementary school. His teacher of geometry often gives h…
Periodic RMQ Problem 动态开点线段树直接搞, 我把它分成两部分, 一部分是原来树上的, 一部分是后来染上去的,两个部分取最小值. 感觉有点难写.. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define PLI pair<LL, int> #…
Tree-String Problem 网上的dfs + kmp 复杂度就是错的, 除非算出根据下一个字符直接转移Next数组直接转移, 而求出Next[ i ][ 26 ]数组和丢进AC自动机里面没有区别.. 然后我的AC自动机还写麻烦了.. 我把全部都求进去求fail然后沿着fail推到目标串, 好蠢啊啊. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk m…
C. Sonya and Problem Wihtout a Legend time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standard output Sonya was unable to think of a story for this problem, so here comes the formal description. You are g…
题目链接: C. Hard problem time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasiliy is fond of solving different tasks. Today he found one he wasn't able to solve himself, so he asks you to help.…
A Trivial Problem Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer m and asks for the number of positive integers n, such that the factorial of n ends with exactly m zeroes. Are you among thos…
Description Sonya was unable to think of a story for this problem, so here comes the formal description. You are given the array containing n positive integers. At one turn you can pick any element and increase or decrease it by 1. The goal is the ma…