CodeForces Round 200 Div2
这次比赛出的题真是前所未有的水!只用了一小时零十分钟就过了前4道题,不过E题还是没有在比赛时做出来,今天上午我又把E题做了一遍,发现其实也很水.昨天晚上人品爆发,居然排到Rank 55,运气好的话没准能领到T-shirt.除此之外,锁上程序之后,看到一个人数组开小了,我还提交了一个大数据,成功Hack了一次,然后Room排名顿时升到第1.


# | When | Who | Problem | Lang | Verdict | Time | Memory |
---|---|---|---|---|---|---|---|
4474604 | Sep 15, 2013 8:05:15 AM | OIer | E - Read Time | GNU C++ | Accepted | 186 ms | 1536 KB |
4474587 | Sep 15, 2013 8:00:16 AM | OIer | E - Read Time | GNU C++ | Wrong answer on test 4 | 30 ms | 800 K |


# | When | Who | Problem | Lang | Verdict | Time | Memory |
---|---|---|---|---|---|---|---|
4466117 | Sep 14, 2013 8:42:37 PM | OIer | D - Alternating Current | GNU C++ | Accepted | 30 ms | 200 KB |
4465840 | Sep 14, 2013 8:39:38 PM | OIer | D - Alternating Current | GNU C++ | Runtime error on pretest 7 | 30 ms | 100 KB |
4464111 | Sep 14, 2013 8:18:06 PM | OIer | C - Rational Resistance | GNU C++ | Accepted | 30 ms | 0 KB |
4461097 | Sep 14, 2013 7:48:16 PM | OIer | B - Simple Molecules | GNU C++ | Accepted | 30 ms | 0 KB |
4459261 | Sep 14, 2013 7:36:06 PM | OIer | A - Magnets | GNU C++ | Accepted | 62 ms | 0 KB |
A. Magnets
time limit per test 1 second
memory limit per test 256 megabytes
input standard input
output standard output
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other. Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own.
Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.
Input
The first line of the input contains an integer n (1 ≤ n ≤ 100000) — the number of magnets. Then n lines follow. The i-th line (1 ≤ i ≤ n) contains either characters "01", if Mike put the i-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.
Output
On the single line of the output print the number of groups of magnets.
Sample test(s)
Input
6 10 10 10 01 10 10
Output
3
Input
4 01 01 10 10
Output
2
Note
The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets. The second testcase has two groups, each consisting of two magnets.
题意:N块磁铁,0表示N极,1表示S极,同性相斥,异性相吸.把块磁铁排成一行,判断形成了几个大块.
思路:纯模拟.
#include<stdio.h>
int main()
{
int N;
char str[],cur[];
scanf("%d",&N);
scanf("%s",str);
int T=;
for (int i=;i<N;i++)
{
scanf("%s",cur);
if (cur[]==str[]) T++;
str[]=cur[];
str[]=cur[];
}
printf("%d\n",T);
return ;
}
1 second
256 megabytes
standard input
standard output
Mad scientist Mike is busy carrying out experiments in chemistry. Today he will attempt to join three atoms into one molecule.
A molecule consists of atoms, with some pairs of atoms connected by atomic bonds. Each atom has a valence number — the number of bonds the atom must form with other atoms. An atom can form one or multiple bonds with any other atom, but it cannot form a bond with itself. The number of bonds of an atom in the molecule must be equal to its valence number.
Mike knows valence numbers of the three atoms. Find a molecule that can be built from these atoms according to the stated rules, or determine that it is impossible.
The single line of the input contains three space-separated integers a, b and c (1 ≤ a, b, c ≤ 106) — the valence numbers of the given atoms.
If such a molecule can be built, print three space-separated integers — the number of bonds between the 1-st and the 2-nd, the 2-nd and the 3-rd, the 3-rd and the 1-st atoms, correspondingly. If there are multiple solutions, output any of them. If there is no solution, print "Impossible" (without the quotes).
Note
The first sample corresponds to the first figure. There are no bonds between atoms 1 and 2 in this case. The second sample corresponds to the second figure. There is one or more bonds between each pair of atoms. The third sample corresponds to the third figure. There is no solution, because an atom cannot form bonds with itself. The configuration in the fourth figure is impossible as each atom must have at least one atomic bond.
题意:有3个原子,它们的化合价分别为a,b,c,假设不能和自身形成共价键,问能否由这3个原子构成1个分子,如果能,输出一种可行解,否则输出"Impossible".
思路:枚举第一个原子和第二个原子见得共价键数目,其余两对原子间的共价键数可以O(1)确定,关键是判定条件
1.两两间形成的共价键数非负.
2.两两间形成的共价键数中最多有两个0(排除图4中的情况)
3.p[1]+p[3]==v[1],保证解得正确性
#include<stdio.h>
int main()
{
int v[],p[];
for (int i=;i<=;i++) scanf("%d",&v[i]);
bool flag=false;
for (int i=;i<=v[];i++)
{
p[]=i;
p[]=v[]-i;
p[]=v[]-p[];
if (p[]+p[]!=v[]) continue;
int T=;
for (int i=;i<=;i++)
if (p[i]==) T++;
if (T>=) continue;
if (p[]>= && p[]>= && p[]>=)
{
flag=true;
break;
}
}
if (flag) printf("%d %d %d\n",p[],p[],p[]);
else printf("Impossible\n");
return ;
}
1 second
256 megabytes
standard input
standard output
Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.
However, all Mike has is lots of identical resistors with unit resistance R0 = 1. Elements with other resistance can be constructed from these resistors. In this problem, we will consider the following as elements:
- one resistor;
- an element and one resistor plugged in sequence;
- an element and one resistor plugged in parallel.
With the consecutive connection the resistance of the new element equals R = Re + R0. With the parallel connection the resistance of the new element equals . In this case Re equals the resistance of the element being connected.
Mike needs to assemble an element with a resistance equal to the fraction . Determine the smallest possible number of resistors he needs to make such an element.
The single input line contains two space-separated integers a and b (1 ≤ a, b ≤ 1018). It is guaranteed that the fraction is irreducible. It is guaranteed that a solution always exists.
Print a single number — the answer to the problem.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is recommended to use the cin, cout streams or the %I64d specifier.
In the first sample, one resistor is enough.
In the second sample one can connect the resistors in parallel, take the resulting element and connect it to a third resistor consecutively. Then, we get an element with resistance . We cannot make this element using two resistors.
题意:用最少的1Ω电阻拼出指定阻值(a/b)电阻.元件之间可以以串联或并联的方式连接.
思路: 显然电阻越并越小,a/b的整数部分可以串联若干1Ω电阻解决.此时,有这样一条重要结论:如果最少用K个电阻构成a/bΩ电阻,那么b/a也需K个(只需改变所有的串并联关系即可).所以此时若b>a,只需交换a,b的值,重复上一步骤.
#include<stdio.h>
int main()
{
__int64 a,b,T=;
scanf("%I64d%I64d",&a,&b);
while (a!=b)
{
if (a==) break;
if (a<b)
{
__int64 tmp=a;
a=b;
b=tmp;
}
T+=a/b;
a%=b;
}
if (a>) T++;
printf("%I64d\n",T);
return ;
}
1 second
256 megabytes
standard input
standard output
Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again.
The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view):
Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut.
To understand the problem better please read the notes to the test samples.
The single line of the input contains a sequence of characters "+" and "-" of length n (1 ≤ n ≤ 100000). The i-th (1 ≤ i ≤ n) position of the sequence contains the character "+", if on the i-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise.
Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled.
The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses.
In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled:
In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher:
In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself:
题意:两根两端固定的电线经过N个节点的交叉,问是否能将电线分成完全不相交的状态.'+'表示交叉点处火线在上边,'-'表示交叉点处零线在上边.
思路:显然,当连续出现两个'+'或两个'-'时,将这一部分去掉对最终结果没有影响.所以可以用栈来解决这个问题.从左往右扫描序列当栈为空或栈顶元素与当前元素不同时将当前元素入栈.否则将栈顶元素弹出.若最终得到空栈,则可以分开.
#include<stdio.h>
#include<string.h>
int main()
{
char str[],s[],T=;
scanf("%s",str);
int L=strlen(str);
if (L%==)
{
printf("No\n");
return ;
}
s[]=str[];
for (int i=;i<L;i++)
{
if (s[T]==str[i] && T>)
{
T--;
continue;
}
else
{
T++;
s[T]=str[i];
}
}
if (T==) printf("Yes\n");
else printf("No\n");
return ;
}
1 second
256 megabytes
standard input
standard output
Mad scientist Mike does not use slow hard disks. His modification of a hard drive has not one, but n different heads that can read data in parallel.
When viewed from the side, Mike's hard drive is an endless array of tracks. The tracks of the array are numbered from left to right with integers, starting with 1. In the initial state the i-th reading head is above the track number hi. For each of the reading heads, the hard drive's firmware can move the head exactly one track to the right or to the left, or leave it on the current track. During the operation each head's movement does not affect the movement of the other heads: the heads can change their relative order; there can be multiple reading heads above any of the tracks. A track is considered read if at least one head has visited this track. In particular, all of the tracks numbered h1, h2, ..., hn have been read at the beginning of the operation.
Mike needs to read the data on m distinct tracks with numbers p1, p2, ..., pm. Determine the minimum time the hard drive firmware needs to move the heads and read all the given tracks. Note that an arbitrary number of other tracks can also be read.
The first line of the input contains two space-separated integers n, m (1 ≤ n, m ≤ 105) — the number of disk heads and the number of tracks to read, accordingly. The second line contains n distinct integers hi in ascending order (1 ≤ hi ≤ 1010, hi < hi + 1) — the initial positions of the heads. The third line contains m distinct integers pi in ascending order (1 ≤ pi ≤ 1010, pi < pi + 1) - the numbers of tracks to read.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is recommended to use the cin, cout streams or the %I64d specifier.
Print a single number — the minimum time required, in seconds, to read all the needed tracks.
The first test coincides with the figure. In this case the given tracks can be read in 2 seconds in the following way:
- during the first second move the 1-st head to the left and let it stay there;
- move the second head to the left twice;
- move the third head to the right twice (note that the 6-th track has already been read at the beginning).
One cannot read the tracks in 1 second as the 3-rd head is at distance 2 from the 8-th track.
题意:有n个磁头,m个位置需要访问.磁头一秒钟可以移动一格,求将m个格子全部访问所需要的最短时间.
思路: 二分答案,对每一种尝试用贪心法判定.假设当前的中间值为T,对于每一个磁头,他可以向左访问一些后折向右,也可以向右访问一些后折向左.
#include<stdio.h>
#define i64 __int64
int N,M;
__int64 H[],R[];
i64 abs(i64 x)
{
if (x<) return -*x;
else return x;
}
i64 max(i64 x,i64 y)
{
return x>y ? x:y;
}
bool judge(i64 T)
{
int cur=;
i64 final;
for (int i=;i<=N;i++)
{
if (abs(H[i]-R[cur])>T) continue;
if (R[cur]==H[i]) cur++;
if (R[cur]<H[i]) final=max(H[i]+T-*(H[i]-R[cur]),H[i]+(T-(H[i]-R[cur]))/);
else final=H[i]+T;
while (R[cur]<=final && cur<=M) cur++;
}
return (cur>M);
}
int main()
{
freopen("input.txt","r",stdin);
while (scanf("%d%d",&N,&M)!=EOF)
{
int i;
for ( i=;i<=N;i++) scanf("%I64d",&H[i]);
for ( i=;i<=M;i++) scanf("%I64d",&R[i]);
i64 l=-,r=abs(H[]-R[])*+abs(H[]-R[M]),mid;
while (l+<r)
{
mid=(l+r)>>;
if (judge(mid)) r=mid;
else l=mid;
}
printf("%I64d\n",r);
}
return ;
}
CodeForces Round 200 Div2的更多相关文章
- Codeforces Round #539 div2
Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...
- 【前行】◇第3站◇ Codeforces Round #512 Div2
[第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...
- Codeforces Round#320 Div2 解题报告
Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...
- Codeforces Round #564(div2)
Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...
- Codeforces Round #361 div2
ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #incl ...
- Codeforces Round #626 Div2 D,E
比赛链接: Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics) D.Present 题意: 给定大 ...
- CodeForces Round 192 Div2
This is the first time I took part in Codeforces Competition.The only felt is that my IQ was contemp ...
- Codeforces Round #200 (Div. 1)A. Rational Resistance 数学
A. Rational Resistance Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/343 ...
- Codeforces Round #327 (Div2) A~E
CodeForces 591A 题意:在距离为L的两端A,B,相向发射魔法,a(以P1的速度)-->B,A<--b(以P2的速度).假设a-->B,途中相遇,则返回到原点A<- ...
随机推荐
- [Effective JavaScript 笔记]第26条:使用bind方法实现函数的柯里化
bind方法的作用,除了有绑定函数到对象外,我们来看看bind方法的一些其它应用. 简单示例 例子:假设有一个装配URL字符串的简单函数.代码如下 function simpleURL(protoco ...
- xcode注释
新开的项目需要先开发iOS版本,所以又把好久没写的iOS捡起来了,之前都是手动注释,最近是越来越懒了,所以在网上找了一个自动注释的插件,啊哈,其实有时候还真的挺怀念用Eclipse的时候,不过不用羡慕 ...
- iOS团队开发者测试
那么你需要在你下载证书的那个电脑上从钥匙串-->选择证书-->右键到处证书,保存为.p12的证书,以后这个证书拷贝到任何电脑上去都是可以使用的! 本来只有一台电脑可以测试, 现在要团队开发 ...
- vim在选中的几行中查找并替换
(文章是从我的个人主页上粘贴过来的, 大家也可以访问我的主页 www.iwangzheng.com) 使用vim编辑器是能带来很大的便捷的,如何替换选中的多行中的某个单词呢. 先选中,按下冒号,左下方 ...
- Bmob用户管理操作
注册用户 BmobUser bu = new BmobUser(); bu.setUsername("sendi"); bu.setPassword("123456&qu ...
- 又是一个二模02,不过day2
话说比较简单.除了第三题不会写平衡树啊你妹!!边做边写吧. 机智的链接~机智的链接~机智的链接~机智的链接~机智的链接~机智的链接~机智的链接~机智的链接~机智的链接~机智的链接~机智的链接~机智的链 ...
- jQuery基础 - 改变CSS样式
jQuery提供css()的方法来实现嵌入式改变元素样式,css()方法在使用上具有多样性.其中一种接受两个输入参数:样式属性和样式值,它们之间用逗号分开.比如我们要改变链接颜色,我们可以使用下面的代 ...
- 【转】 Mybatis/Ibatis,数据库操作的返回值
该问题,我百度了下,根本没发现什么有价值的文章:还是看源代码(详见最后附录)中的注释,最有效了!insert,返回值是:新插入行的主键(primary key):需要包含<selectKey&g ...
- sys.path和os.path
sys.path和os.path1.sys.path是python搜索模块的路径集合,是个list:os.path是os的一个模块,是操作文件和目录的模块 2.sys.path和PYTHONPATH首 ...
- 22.整数二进制表示中1的个数[Get1BitCount]
[题目] 输入一个整数,求该整数的二进制表达中有多少个1.例如输入10,由于其二进制表示为1010,有两个1,因此输出2. [分析] 如果一个整数不为0,那么这个整数至少有一位是1.如果我们把这个整数 ...