题意:给定一个数列,每次操作仅仅能将某个数乘以2或者除以2(向下取整). 求最小的操作次数使得全部的数都变为同样值. 比赛的时候最后没实现.唉.之后才A掉.開始一直在想二分次数,可是半天想不出怎么推断.后来发现事实上每一个数都能变成的数非常少非常少(最多400个不到).于是想到用数学方法+一点暴力,可惜时间不够了. 也不能全然算是数论题.仅仅是用到了一些数学思想.须要一点预处理,后面的计算中还会用到二分的技巧. 对某个数n,设n = s*2^r(当中s为奇数),则n能变成这样一些数:s*2…
C. Amr and Chemistry Problem's Link: http://codeforces.com/problemset/problem/558/C Mean: 给出n个数,让你通过下面两种操作,把它们转换为同一个数.求最少的操作数. 1.ai = ai*2 2.ai = ai/2 (向下取整) analyse: 基本思路:首先枚举出每个数能够到达的数字并且记录下到达该数组需要的步数,然后从到达次数为n次的数字中选择步数最小的即为答案. 对于一个数字Ai,它可以变换得到的数字可…
点击打开链接 Amr and Chemistry time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment. Amr has n di…
Codeforces 558C 题意:给n个数字,对每一个数字能够进行两种操作:num*2与num/2(向下取整),求:让n个数相等最少须要操作多少次. 分析: 计算每一个数的二进制公共前缀. 枚举法亦可. /* *Author : Flint_x *Created Time : 2015-07-22 12:33:11 *File name : whust2_L.cpp */ #include<iostream> #include<sstream> #include<fstr…
题意: n个数.每次能够选一个数 让其 *=2 或者 /=2 问至少操作多少次使得全部数相等. 思路: 对于每一个数,计算出这个数能够变成哪些数,以及变成那个数的最小步数,用两个数组保存 cnt[i] 表示序列中有cnt个数能够变成i step[i] 表示能变成i的 那些数 变成i的花费和是多少. 当中.遇到奇数的时候要特殊处理一下: 比方,7 能够通过 /2 然后 *2得到6,也就是说不论什么奇数 i (不包含1)都能够通过2次操作变为 i -1: 代码例如以下: #include<cstdi…
题目链接: C. Amr and Chemistry time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment. Amr has n …
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment. Amr has n different types of chemicals. E…
C. Amr and Chemistry Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/558/problem/C Description Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment. Amr has n different type…
Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment. Amr has n different types of chemicals. Each chemical i has an initial volume of ai liters. For this experiment, Amr has to mix all the chemicals…
C. Amr and Chemistry time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment. Amr has n differ…
链接:http://codeforces.com/problemset/problem/558/C C. Amr and Chemistry time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Amr loves Chemistry, and specially doing experiments. He is preparing…
[Codeforces 639F] Bear and Chemistry(Tarjan+虚树) 题面 给出一个n个点,m条边的无向图(不保证连通,可能有自环和重边),有q次询问,每次询问给出p个点和q条边,判断加上q条边后,这p个点中的任意一个点对(x,y)是否都满足:能从x走到y,再从y走到x,不经过重复的边.询问强制在线. \((1 ≤ n, q≤ 300 000, 0 ≤ m ≤ 300 000,\sum p \leq 300\ 000,\sum q \leq 300\ 000)\) 分析…
C. Amr and Chemistry time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment. Amr has n differ…
C. Amr and Chemistry time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment. Amr has n differ…
http://codeforces.com/problemset/problem/558/C 分析:将每一个数在给定范围内(10^5)可变成的数(*2或者/2)都按照广搜的方式生成访问一遍,标记上访问的步数,之后遍历区间找到被访问次数达到n(所有数都可以变成这个数)并且标记的需要步数最少即可. 注意:当是奇数的时候,例如11(11/2=5 5*2=10),按照这么算(除2后再乘2)回重新得到一个新的数 #include <cstdio> #include <cstring> #in…
题目链接:http://codeforces.com/problemset/problem/558/C 题意:把n个数变成相同所需要走的最小的步数易得到结论,两个奇数不同,一直×2不可能有重叠枚举每个数可能到得所有值,以及统计达到该值的时候已经走的步数最终答案就是1到up中num[i]最小的数 Examples input output 2 input output 5 Note In the first sample test, the optimal solution . In the se…
DZY Loves Chemistry Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 445B Description DZY loves chemistry, and he enjoys mixing chemicals. DZY has n chemicals, and m pairs of them will re…
转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://codeforces.com/problemset/problem/445/B --------------------------------------------------------------------------------------------------------------------------------------------…
题目链接:http://codeforces.com/problemset/problem/558/B 题目意思:给出一个序列,然后找出出现次数最多,但区间占用长度最短的区间左右值. 由于是边读入边比较,因此问题最关键的是,记录每个数第一次出现的位置,即左值.因为要保证次数是出现最多,因此需要一个cnt[]数组来记录出现次数.然后当最多出现次数与当前cnt[x]次数相同时,要选择区间较短的,再更新左右区间值. 赛中短路竟然想不出来~~~泪啊~~泪啊- >_< #include <iost…
题目链接:http://codeforces.com/problemset/problem/507/B 题目意思:给出圆的半径,以及圆心坐标和最终圆心要到达的坐标位置.问最少步数是多少.移动见下图.(通过圆上的边固定转动点,然后转动任意位置,圆心就会移动了,这个还是直接看图吧) 解题的思路就是,两点之间,距离最短啦----要想得到最少步数,我们需要保证圆心在这条连线上移动,每次转动的角度是180度,而每步移动的距离是2r,直到两个圆交叉,要注意最后一步转动的角度可能会小于180度.最后就是注意精…
题目链接:http://codeforces.com/problemset/problem/558/C 题意:给出n个数,让你通过下面两种操作,把它们转换为同一个数.求最少的操作数. 1.ai = ai*2 2.ai = ai/2,向下取整 思路: 可以除以二 或者 乘以二,就相当于位运算的右移和左移.用两个数组,vis 数组, cnt 数组.刚开始都初始化为0: vis[i] 表示 i 这个数可以由几个数转化而来,cnt[i] 表示题目给出的 n 个数全部转化为 i 需要的操作数. 首先遍历数…
Amr loves Geometry. One day he came up with a very interesting problem. Amr has a circle of radius r and center in point (x, y). He wants the circle center to be in new position (x', y'). In one step Amr can put a pin to the border of the circle in a…
题目链接:http://codeforces.com/problemset/problem/445/B 题目意思:给出 n 种chemicals,当中有 m 对可以发生反应.我们用danger来评估这些chemicals的厉害程度.厉害程度是这样的:一瓶什么都不加的瓶子的danger 为 1,如果有一对(即 m = 1)chemicals 能够发生反应,那么这个danger就会加倍(1*2).不过要注意一点,对于 1 2: 1 3: 2 3,danger为 4 而不为 8.(因为这个条件限制了:…
B. Amr and The Large Array time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller. Amr doesn't c…
题意:有一个数组.如今要削减它的尺寸.数组中同样元素的个数的最大值为数组的魅力值,要求削减后魅力值不能降低,同一时候要尽可能的把尺寸减到最小 分析:水题,主要是不要想复杂了.还有就是沉下心来做 代码: #include<iostream> #include<cstring> #include<algorithm> #define INF 1000000007 #define max(a,b) a>b?a:b using namespace std; int n,a…
题意: 有N种药剂编号 1 ~ N,然后有M种反应关系,这里有一个试管,开始时危险系数为 1,每当放入的药剂和瓶子里面的药剂发生反应时危险系数会乘以2,否则就不变,给出N个药剂和M种反应关系,求最大的危险系数. 思路: 我们假设 1 ~ N   有 M 种反应关系 ,若果有反应关系的我们可以把他们看成是一个集合  ,假设这M种反应构成了 T个集合,那么把这T个集合中的元素依次放入试管,有几个不发生反应呢?当然是T个了,把每个集合看成是一课树,根节点和其子节点反应,这个子节点又和它的子节点发生反应…
好吧,再一次被水题虐了. A. Lala Land and Apple Trees 敲码小技巧:故意添加两个苹果树(-1000000000, 0)和(1000000000, 0)(前者是位置,后者是价值). B. Amr and The Large Array 找出最长的是哪些数字,然后再对这些数字找最大区间. 我居然还想用两个指针加有限队列维护!TAT C. Amr and Chemistry 首先,我们可以计算由x变为y的代价.O(1) 于是我枚举了\(a_0\)可以变为哪些数(最多\(m^…
[比赛链接]click here~~ A. Lala Land and Apple Trees: [题意]: AMR住在拉拉土地. 拉拉土地是一个很漂亮的国家,位于坐标线.拉拉土地是与著名的苹果树越来越随处可见. 拉拉土地恰好n苹果树.树数i位于位置xi和具有人工智能的苹果就能够了增长.阿姆鲁希望从苹果树收集苹果. AMR眼下维持在X =0的位置.在開始的时候,他能够选择是否去左边或右边.他会在他的方向继续下去.直到他遇见一棵苹果树,他之前没有參观.他会採取全部的苹果.然后扭转他的方向.继续走这…
前言 前一阶段对MVC模式及其衍生模式做了一番比较深入的研究和实践,这篇文章也算是一个阶段性的回顾和总结. 经典MVC模式 经典MVC模式中,M是指业务模型,V是指用户界面,C则是控制器,使用MVC的目的是将M和V的实现代码分离,从而使同一个程序可以使用不同的表现形式.其中,View的定义比较清晰,就是用户界面.但对于Model和Controller的定义则较为模糊,以致在项目实践中对它们的职责产生了很多不同的理解.其中比较主流的有下面两种. 1.闭环党 比较传统,问题是Model和Contro…
C. Amr and Chemistry time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment. Amr has n differ…