【Codeforces 349B】Color the Fence】的更多相关文章

[链接] 我是链接,点我呀:) [题意] 让你组成一个只由1~9组成的数字 每个数字需要的paint数字给定. 让你组成一个最大的数字,且所有数字的paint的总和不超过v. [题解] 先求出a中的最小值mi 最后的长度显然就是a/mi啦 然后从高位到低位,优先让高位优先选择大的数字就好. (判断这一位能否为i的条件就是,后面的所有位置全都选择mi 看看会不会超过剩余的paint数量就好 [代码] import java.io.*; import java.util.*; public clas…
Codeforces 1132 C 题意:给一些区间\([l_i,r_i]\),从中删掉两个,求剩下的区间最多能够覆盖的格子数量. 思路:首先枚举第一个删掉的区间,然后我们可以通过差分来求出每个格子被多少个区间覆盖了,随后求出所有格子中被\(1\)个区间覆盖的数量的前缀和,再枚举第二个删掉的区间,找删掉的\(1\)个区间覆盖的最少的即为答案. Codeforces 1132 C 分析 tataky: 首先我们将所有的互不包含的区间们放在\(v\)里,然后看被包含的区间有多少,如果超过2个就直接输…
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=2000),问满足[数列长度是k && 数列中每一个元素arr[i]在1~n之间 && 数列中元素可以重复]的数列有多少个?结果对10^9+7取余 解题思路:dp[i][j]表示长度是j,最后一位是i的种数 if(kk%i==0) dp[kk][j+1]+=dp[i][j] #inc…
[题目链接]:http://codeforces.com/problemset/problem/234/F [题意] 你有n块板要凃油漆; 然后每块板有高度h[i];(宽度都为1) 然后每块板只能凃同一种颜色;(不同板则可以涂不同颜色); 板是按下标顺序放着的; 相邻两个板i和j之间; 相同的高度,如果都有板,且它们的颜色不同,则不好的程度+1; 然后; 你能涂a平方单位的红漆,b平方单位的绿漆; 问你把这n块板涂满的最小"不好程度"; 或输出不能涂满; [题解] 记忆化搜索; 在记录…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special. Alyona is a capricious girl so afte…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output After Vitaly was expelled from the university, he became interested in the graph theory. Vitaly especially liked the cycles of an odd length in w…
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard output Anton is growing a tree in his garden. In case you forgot, the tree is a connected acyclic undirected graph. There are n vertices in the tree, e…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k. Balls of the same colo…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Nothing is eternal in the world, Kostya understood it on the 7-th of January when he saw partially dead four-color garland. Now he has a goal to…
time limit per test2.5 seconds memory limit per test256 megabytes inputstandard input outputstandard output One tradition of welcoming the New Year is launching fireworks into the sky. Usually a launched firework flies vertically upward for some peri…
[题目链接]:http://codeforces.com/contest/776/problem/D [题意] 每个门严格由两个开关控制; 按一下开关,这个开关所控制的门都会改变状态; 问你能不能使所有的门都打开(同时); [题解] /* 对于每个门, 有两个开关连接着它; 用一条边连接这两个开关 则如果这个门的状态是关的, 则这条边的边权为1 表示它们俩的颜色不能一样; (也即这两个开关只能改变一个) 也即要1开1关; 如果这个门的状态是开的 则这条边的边权为0: 表示它们俩的颜色相同; 即同…
[题目链接]:http://codeforces.com/contest/782/problem/C [题意] 给你一棵树 让你满足要求 ->任意相连的3个节点的颜色不能相同 的情况下进行染色 问最少需要的颜色数目 [题解] 这种染色题一般只要贪心染就好了 即之前没出现过的颜色最小的颜色就好; (这里的之前指的是当前枚举的节点和它的父亲节点以及这个节点的儿子节点们..) 感觉很多题都要顺着题意去做啊; [完整代码] #include <bits/stdc++.h> using names…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built n towers in a row. The i-th tower is made of h…
time limit per test2 seconds memory limit per test512 megabytes inputstandard input outputstandard output Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gemstones, the i-th of which has color ci. The goal of the…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output On her way to programming school tiger Dasha faced her first test - a huge staircase! The steps were numbered from one to infinity. As we know,…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Each New Year Timofey and his friends cut down a tree of n vertices and bring it home. After that they paint all the n its vertices, so that the…
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q个操作; 有以下两种类型 ①将第i个连通块里面灯取反 ②询问你(x1,y1)(x2,y2)这个矩形区域内灯的权值的和; [题解] 要用到二维的树状数组; 取反操作只要O(1)就能完成; 即先不管它是什么,取反就是了; 然后在询问的时候,直接用二维树状数组累加; 这里的累加可能是减也可能是加; 也可能…
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小; [题解] 首先明确n<=2的时候是无解的. n>2之后都有解; 这里设 n2+b2=a2 则有 n2=a2−b2 也即 n2=(a+b)∗(a−b) 这里对n分两类讨论; ① n为奇数 则令 a−b=1 a+b=n2 这样 2∗a=n2+1 因为n是奇数所以右边是个偶数; 得出来的a就是整数了…
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出一个符合要求的序列; [题解] 这里 00和11可以确定出序列中0和1的个数; 但有边缘数据 00如果为0代表什么? ->没有0或者是有1个0 11如果为0代表什么? ->没有1或者是有1个1 对这两种情况需要特判一下(两种情况的特判需要用到01和10的数量) 看代码吧. 然后这两种情况排除之后;…
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; 则肯定要有一个点不走; ->哪个点呢; 就是排序之后,最左边或最右边那个点不走; 不可能是中间的点. 因为既然你要走的点不是最边上的点,那么你肯定会在去最边上的点的时候路过那个你选择不走的点; 这个点的选取就没有意义了: 然后对于两种情况; 还有两种可能,就是先往左一直(不回头不然更长)走然后再往…
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一个; 即b->a或是a>z; 然后使得剩下的字符串的字典序最小; [题解] 优先更改前面的字符; 所以遇到第一个不是a的字符->改! 从那个字符开始只要不是a就一直改就好; hack点: 有说 exactly once->也就是说 像 aaa 不能全都不改; 把最后那个a改成z(损失最…
[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = Sj - Si f(i,j) = (i-j)^2 + (Si - Sj)^2 观察这个式子,我们发现可以用类似于平面最近点对的算法来求解该问题 [代码] #include<bits/stdc++.h> using namespace std; #define MAXN 100010 const…
[题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using namespace std; #define MAXN 200010 ,nx = -,len,i,rkb,rkc; ],tmp[MAXN<<]; template <typename T> inline void read(T &x) { ; x = ; char c = g…
[题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案是唯一的; 则输出那个方案,否则,输出不唯一; [题解] 记录每个点的度; 每个点的度,为这个点4个方向上空格的个数; 优先处理度数为1的点; 这些点的摆放方式肯定是唯一的; 摆完这些点(两个之后),与之相连的点的度数都减1: 看看有没有新的度数为1的点; 很像拓扑排序对吧. 最后看看占据的点是不是…
[题目链接]:http://codeforces.com/contest/515/problem/C [题意] 定义f(n)=n这个数各个位置上的数的阶乘的乘积; 给你a; 让你另外求一个不含0和1的最大的数字b; 使得f(a)==f(b) [题解] 对a的每一个大于1的数字进行分解; 看看它能够组合成的最多的比它小的数字的阶乘的乘积是哪些; 比如 4!=3!∗(2!)2 每个都找最多数目的:数目相同找大的数的组合; 求出2..9!的组合就好; 最后根据每个数字的分解方案; 求出所有的数字; 然…
[题目链接]:http://codeforces.com/contest/515/problem/B [题意] 第i天选择第i%n个男生,第i%m个女生,让他们一起去吃饭; 只要这一对中有一个人是开心状态,另外一个人也能变成开心状态; 且开心之后就一直开心了: 给你n个男生,m个女生的状态(是否开心); 问你是否到了某一天所有人都会变的开心: [题解] 那个i%n和i%m的循环肯定有循环节的; 找到那个循环节的长度; 每次在循环节内尝试用上述办法,看看有没有办法让某些人从不开心变为开心; 如果可…
[题目链接]:http://codeforces.com/contest/515/problem/A [题意] 每次只能走到相邻的四个格子中的一个; 告诉你最后走到了(a,b)走了多少步->s (你一开始在位置(0,0) 问你可不可能; [题解] 先算出从0,0走到(a,b)的步数(最短)->temp; 之后,如果s-temp为偶数就可行,否则不可行; (s< temp肯定不行); 为偶数的话,去了可以再回来. 没看到a,b能为负数.. [Number Of WA] 1 [完整代码] #…
[题目链接]:http://codeforces.com/contest/761/problem/E [题意] 给你一棵树,让你在平面上选定n个坐标; 使得这棵树的连接关系以二维坐标的形式展现出来; [题解] dfs来搞; 显然如果某个点的度数大于4就无解. 初始坐标为(0,0)然后每一层的边的长度变为上一层长度的1/2 初始层的长度为2 30   这样可以保证每层节点都不会和上一层的相交; 因为2 i >2 1 +2 2 +...+2 i−1   又因为最多只有30个节点,所以这么做肯定是可以…
[题目链接]:http://codeforces.com/contest/764/problem/D [题意] 给你n个矩形,以左下角坐标和右上角坐标的形式给出; (保证矩形的边长为奇数) 问你有没有染色方案,使得这n个矩形,任意两个相邻矩形的颜色不一样; (只有4种颜色可以选择); [题解] 因为矩形的边长为奇数; 所以对于左下角来说; 右上角的横纵坐标的奇偶性分别和左下角的横纵坐标的奇偶性都不同; (因为一个数加上奇数之后奇偶性发生改变); 按照这个原理; 我们只要考虑左下角那个坐标就好了:…
[题目链接]:http://codeforces.com/contest/792/problem/D [题意] 给你一棵满二叉树; 给你初始节点; 给你若干个往上走,左走,右走操作; 让你输出一系列操作结束之后节点的位置; [题解] 这个节点的标志方式类似树状数组; 用树状数组左走右走就好; L->x-=lowbit(x)/2; R->x+=lowbit(x)/2; U->先假设x是左儿子,然后依照规则求出父亲F,然后看看F的左儿子是不是真的是x,是的话爸爸就是F,否则x是右儿子,然后根…