codeforces Dima and Bacteria】的更多相关文章

题意:给出n,m和k,表示有n个细菌,m种仪器和k种细菌,给出k种细菌的数量ci,然后每个细菌按照种类排成一排(所以有第i种细菌的序号从∑(1≤j≤i-1)cj + 1 到∑(1≤j≤i)cj):接下来给出m种仪器,有u,v,x三个值,表示说从可以在第u,v号细菌之间移动能量,代价为x.请帮助判断说这些细菌是否正确,正确的前提条件是说同种细菌之间移动能量为0,如果正确的话,给出两两细菌(种类)间移动能量的最小值. 思路:并差集+floyd: #include <cstdio> #include…
题目链接:http://codeforces.com/problemset/problem/400/D 题目大意: 给定n个集合,m步操作,k个种类的细菌, 第二行给出k个数表示连续的xi个数属于i集合. 当某个种类之间两两交换的值都为0可行解,则输出所有种类之间交换的最小值:否则输出No 解题思路:当两点之间的距离为0时并查集到一个集合中,只需保证最终同一种类的细菌都在一个并查集中则是符合条件的可行解,再用FLOYD找最短路即可 #include<cmath> #include<cst…
题意:给出n个点,分别属于k个集合,判断每个集合里面的点的距离都为0,为0的话输出yes,并输出任意两个集合之间的最短路 这道题目有两个地方不会处理, 先是n个点,分别属于k个集合,该怎么记录下来这里, 然后就是判断每个集合里面的点的距离是否为1,这里可以用并查集来做,如果在输入点的时候,距离为0,就将这两点合并 最后判断每个点,如果他们同属于一个集合,判断它俩的根是否一样就可以了 最后用floyd求最短路 #include<iostream> #include<cstdio> #…
You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to se…
题意:给你一个无向有权的图,图上的点被分成了几类,对于同类的点你需要判断它们之间相互的最短距离是不是0.满足这个条件之后要输出的是类与类之间的最短距离的矩阵.点给到10^5这么多,判断同类的点显然不能跑最短路,所以直接的方法必然是并查集,对边为0的点做一次并查集,对同类的点判一下find(x)==find(y)就可以了. 然后就是将同类的点抽象出一个新的点,这个时候只有500个点,然后就可以跑一下floyd了. 题意有坑的地方,所以没有AC比赛的时候. 这题倒是很好的练了一下基础的内容并查集和f…
题意: 题目大意:给出n,m和k,表示有n个细菌,m种仪器和k种细菌,给出k种细菌的数量ci,然后每个细菌按照种类排成一排(所以有第i种细菌的序号从∑(1≤j≤i-1)cj + 1 到∑(1≤j≤i)cj):接下来给出m种仪器,有u,v,x三个值,表示说从可以在第u,v号细菌之间移动能量,代价为x.请帮助博士判断说这些细菌是否正确,正确的前提条件是说同种细菌之间移动能量为0,如果正确的话,给出两两细菌(种类)间移动能量的最小值. AC代码: #include <iostream> #inclu…
A - Inna and Choose Options Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Description There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of…
A. Inna and Choose Options time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusu…
Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Finding Team Member codeforces 579C A Problem about Polyline codeforces 579D "Or" Game codeforces 579E Weakness and Poorness codeforces 579F LCS Aga…
今天的题目有 6 个. 第一题: CodeForces - 400D  Dima and Bacteria 这个题实际是不难的,难的可能在题意的理解上还有题干有点长,这个题很考察题意上面,知识点很熟悉,并查集和Floyd. 具体题解地址:http://www.cnblogs.com/dwtfukgv/p/7126059.html 第二题:CodeForces - 384E  Propagating tree 这个题确实是有难度的,当然主要是在时间上面,其实这个我是防AK的,然后这个题很容易理解,…
D. Dima and Bacteria time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Dima took up the biology of bacteria, as a result of his experiments, he invented k types of bacteria. Overall, there a…
题目链接: http://codeforces.com/problemset/problem/272/D D. Dima and Two Sequences time limit per test2 secondsmemory limit per test256 megabytes 问题描述 Little Dima has two sequences of points with integer coordinates: sequence (a1, 1), (a2, 2), ..., (an, …
D. Dima and Lisa Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/problem/D Description Dima loves representing an odd number as the sum of multiple primes, and Lisa loves it when there are at most three primes. Help them…
1e9 以内的判断一个数是否是素数,可以直接朴素的暴力.   这倒题除了考虑1e9以内的素数的判断,还有一个歌德巴赫猜想:任意一个奇数都可一分解为三个素数的和. 第三个结论:素数是密集的,1e9以内,相邻的素数之间的间隔不会大于300,所以直接枚举也不会浪费掉太多的时间.   这里还有一点需要注意的是:朴素的判断是否是素数,i<=saqrt(n).今天的天梯赛由于记错了这个条件,导致没有求出素数,一道二十分的题没有做,好伤心. Dima and Lisa Time Limit:1000MS   …
Dima and Magic Guitar CodeForces - 366E 题意: http://blog.csdn.net/u011026968/article/details/38716425http://vawait.com/2013/11/codeforces-366e/http://www.cnblogs.com/jianglangcaijin/archive/2013/11/25/3441319.html 对于s中任意相邻两个数x和y,都要求在矩形中找出任意两个分别等于x和y的点…
B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following proble…
题目链接:http://codeforces.com/problemset/problem/358/B 题目意思:给出n个单词(假设为word1,word2.word3...wordn)和一句test message,需要判断的是,这个 test message在去除一系列随机插入的英文字符后,是否满足<3word1<3word2<3 ... wordn<3 的结构. 首先要构造出一个参考序列,也就是<3word1<3word2<3 ... wordn<3的…
题目链接:http://codeforces.com/problemset/problem/358/A 题目意思:在横坐标上给出n个不同的点,需要把前一个点跟后一个点(这两个点的顺序是紧挨着的)用一个半圆弧来连接.现在要判断的是这些符合条件的点连接以后,圆弧之间是否相交了.是则输出yes,否则输出no. 假设序列是x1,x2,x3,x4.....xn.相交其实只有两种情况,第一种就是样例已经给出了的:即  x1 < x3 < x2 且 x2 < x4.另外一种情况就是第一种情况的对称位置…
题目链接:http://codeforces.com/problemset/problem/358/D 开始题意理解错,整个就跪了= = 题目大意:从1到n的位置取数,取数的得到值与周围的数有没有取过有关,所有数都要取,求最终得到的最大结果 解题思路:dp题,转移方程如下 dp[i][0]=max(dp[i-1][0]+b[i-1],dp[i-1][1]+c[i-1]) dp[i][1]=max(dp[i-1][0]+a[i-1],dp[i-1][1]+b[i-1]) a,b,c分别表示周围没有…
http://codeforces.com/contest/358/problem/D 题意:给出n个数,每个数取走的贡献与相邻的数有关,如果取这个数的时候,左右的数都还没被取,那么权值为a,如果左右两个数有一个被取走了,那么权值为b,如果左右两个数都被取走了,那么权值为c,求取取走全部数的最大值. 思路:f[i][1][0]代表这个位置在i-1选后才选,f[i][1][1]代表这个位置在i+1选后才选,f[i][0][0]代表这个位置在3个中是第一个选的,f[i][2][0]代表这个位置在3个…
http://codeforces.com/problemset/problem/366/C 题意:在一个冰箱里有n种水果,并且这些水果每一种都有一个美味度和一个卡路里的属性, 小明要从这些水果中选出来一些做一个水果沙拉, 并且要求他的水果沙拉的美味度之和是卡路里和的k倍,问小明是否可以做出这么一个水果沙拉,若不能输出-1,否则输出符合要求的最大的美味值之和. 思路:考虑这样DP:f[i][j]:做到第i个水果,平衡度为j,平衡度的表示:Σa[i]-K*Σb[i],这样就可以dp f[i][j]…
C. Dima and Salad time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to…
dp[i][0]表示i号兔子先于i-1号兔子喂食,dp[i][1]反过来. 倒着DP D. Dima and Hares time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Dima liked the present he got from Inna very much. He liked the present he got…
Sereja and Dima time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Sereja and Dima play a game. The rules of the game are very simple. The players have n cards in a row. Each card contains a n…
题目链接:http://codeforces.com/contest/1151/problem/B 题目大意: 给定一个n*m的矩阵,里面存放的是自然数,要求在每一行中选一个数,把他们异或起来后结果大于0,如果存在一种方案,就把每行所选数的列号输出. 分析: 我们只关注这些数的第i位二进制位,如果存在某一行比如说第k行,这一行中有第i位二进制位为1的数,也有第i位二进制位为0的数,那么可以说,这一行是决定性的行,无论其他行怎么选择,这一行只要根据其他行异或的结果,变通地选择第i位二进制位为0或1…
374C - Inna and Dima 思路:dfs+记忆化搜索 代码: #include<bits/stdc++.h> using namespace std; #define ll unsigned long long #define pb push_back #define mem(a,b) memset(a,b,sizeof(a)) const int INF=0x3f3f3f3f; ][]; ][]; ][]; ][]={,,,,,-,-,}; int n,m; int dfs(i…
Dima and Trap Graph 枚举区间的左端点, 然后那些左端点比枚举的左端点小的都按右端点排序然后并查集去check #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> #define PII pair<…
                                                                       E. Dima and Kicks                                                              time limit per test 2 seconds                                                              memory li…
A. Raising Bacteria time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can…
题目链接:http://codeforces.com/problemset/problem/358/D 题意: 有n个物品A[i]摆成一排,你要按照某一个顺序将它们全部取走. 其中,取走A[i]的收益为: (1)若A[i-1]和A[i+1]都没被取走,则收益为a[i] (2)若A[i-1]和A[i+1]被取走了一个,则收益为b[i] (3)若A[i-1]和A[i+1]都被取走,则收益为c[i] 注:将A[1]的左边和A[n]的右边视为永远有一个取不走的物品. 问你最大收益是多少. 题解: 表示状…