這次比賽出的題真是前所未有的水!只用了一小時(shí)零十分鐘就過(guò)了前4道題,不過(guò)E題還是沒(méi)有在比賽時(shí)做出來(lái),今天上午我又把E題做了一遍,發(fā)現(xiàn)其實(shí)也很水.昨天晚上人品爆發(fā),居然排到Rank 55,運(yùn)氣好的話沒(méi)準(zhǔn)能領(lǐng)到T-shirt.除此之外,鎖上程序之后,看到一個(gè)人數(shù)組開(kāi)小了,我還提交了一個(gè)大數(shù)據(jù),成功Hack了一次,然后Room排名頓時(shí)升到第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極,同性相斥,異性相吸.把塊磁鐵排成一行,判斷形成了幾個(gè)大塊.
思路:純模擬.

#include<stdio.h> int main() { int N; char str[ 5 ],cur[ 5 ]; scanf( " %d " ,& N); scanf( " %s " ,str); int T= 1 ; for ( int i= 1 ;i<N;i++ ) { scanf( " %s " ,cur); if (cur[ 0 ]==str[ 1 ]) T++ ; str[ 0 ]=cur[ 0 ]; str[ 1 ]=cur[ 1 ]; } printf( " %d\n " ,T); return 0 ; }
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 ?≤?10 6 ) — 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個(gè)原子,它們的化合價(jià)分別為a,b,c,假設(shè)不能和自身形成共價(jià)鍵,問(wèn)能否由這3個(gè)原子構(gòu)成1個(gè)分子,如果能,輸出一種可行解,否則輸出"Impossible".
思路:枚舉第一個(gè)原子和第二個(gè)原子見(jiàn)得共價(jià)鍵數(shù)目,其余兩對(duì)原子間的共價(jià)鍵數(shù)可以O(shè)(1)確定,關(guān)鍵是判定條件
1.兩兩間形成的共價(jià)鍵數(shù)非負(fù).
2.兩兩間形成的共價(jià)鍵數(shù)中最多有兩個(gè)0(排除圖4中的情況)
3.p[1]+p[3]==v[1],保證解得正確性

#include<stdio.h> int main() { int v[ 5 ],p[ 5 ]; for ( int i= 1 ;i<= 3 ;i++) scanf( " %d " ,& v[i]); bool flag= false ; for ( int i= 0 ;i<=v[ 1 ];i++ ) { p[ 1 ]= i; p[ 2 ]=v[ 2 ]- i; p[ 3 ]=v[ 3 ]-p[ 2 ]; if (p[ 3 ]+p[ 1 ]!=v[ 1 ]) continue ; int T= 0 ; for ( int i= 1 ;i<= 3 ;i++ ) if (p[i]== 0 ) T++ ; if (T>= 2 ) continue ; if (p[ 1 ]>= 0 && p[ 2 ]>= 0 && p[ 3 ]>= 0 ) { flag = true ; break ; } } if (flag) printf( " %d %d %d\n " ,p[ 1 ],p[ 2 ],p[ 3 ]); else printf( " Impossible\n " ); return 0 ; }
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 R 0 ?=?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
?=?
R
e
?+?
R
0
. With the parallel connection the resistance of the new element equals
. In this case
R
e
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 ?≤?10 18 ). 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)電阻.元件之間可以以串聯(lián)或并聯(lián)的方式連接.?
思路:?顯然電阻越并越小,a/b的整數(shù)部分可以串聯(lián)若干1Ω電阻解決.此時(shí),有這樣一條重要結(jié)論:如果最少用K個(gè)電阻構(gòu)成a/bΩ電阻,那么b/a也需K個(gè)(只需改變所有的串并聯(lián)關(guān)系即可).所以此時(shí)若b>a,只需交換a,b的值,重復(fù)上一步驟.

#include<stdio.h> int main() { __int64 a,b,T = 0 ; scanf( " %I64d%I64d " ,&a,& b); while (a!= b) { if (a== 0 ) break ; if (a< b) { __int64 tmp = a; a = b; b = tmp; } T +=a/ b; a %= b; } if (a> 0 ) T++ ; printf( " %I64d\n " ,T); return 0 ; }
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:

?題意:兩根兩端固定的電線經(jīng)過(guò)N個(gè)節(jié)點(diǎn)的交叉,問(wèn)是否能將電線分成完全不相交的狀態(tài).'+'表示交叉點(diǎn)處火線在上邊,'-'表示交叉點(diǎn)處零線在上邊.
?思路:顯然,當(dāng)連續(xù)出現(xiàn)兩個(gè)'+'或兩個(gè)'-'時(shí),將這一部分去掉對(duì)最終結(jié)果沒(méi)有影響.所以可以用棧來(lái)解決這個(gè)問(wèn)題.從左往右掃描序列當(dāng)棧為空或棧頂元素與當(dāng)前元素不同時(shí)將當(dāng)前元素入棧.否則將棧頂元素彈出.若最終得到空棧,則可以分開(kāi).

#include<stdio.h> #include < string .h> int main() { char str[ 100005 ],s[ 100005 ],T= 1 ; scanf( " %s " ,str); int L= strlen(str); if (L% 2 == 1 ) { printf( " No\n " ); return 0 ; } s[ 1 ]=str[ 0 ]; for ( int i= 1 ;i<L;i++ ) { if (s[T]==str[i] && T> 0 ) { T -- ; continue ; } else { T ++ ; s[T] = str[i]; } } if (T== 0 ) printf( " Yes\n " ); else printf( " No\n " ); return 0 ; }
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 h i . 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 h 1 , h 2 , ... , h n have been read at the beginning of the operation.

?
Mike needs to read the data on m distinct tracks with numbers p 1 , p 2 , ... , p m . 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 ?≤?10 5 ) — the number of disk heads and the number of tracks to read, accordingly. The second line contains n distinct integers h i in ascending order ( 1?≤? h i ?≤?10 10 , h i ?<? h i ?+?1 ) — the initial positions of the heads. The third line contains m distinct integers p i in ascending order ( 1?≤? p i ?≤?10 10 , p i ?<? p i ?+?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個(gè)磁頭,m個(gè)位置需要訪問(wèn).磁頭一秒鐘可以移動(dòng)一格,求將m個(gè)格子全部訪問(wèn)所需要的最短時(shí)間.
思路:?二分答案,對(duì)每一種嘗試用貪心法判定.假設(shè)當(dāng)前的中間值為T(mén),對(duì)于每一個(gè)磁頭,他可以向左訪問(wèn)一些后折向右,也可以向右訪問(wèn)一些后折向左.

#include<stdio.h> #define i64 __int64 int N,M; __int64 H[ 100005 ],R[ 100005 ]; i64 abs(i64 x) { if (x< 0 ) return - 1 * x; else return x; } i64 max(i64 x,i64 y) { return x>y ? x:y; } bool judge(i64 T) { int cur= 1 ; i64 final; for ( int i= 1 ;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- 2 *(H[i]-R[cur]),H[i]+(T-(H[i]-R[cur]))/ 2 ); 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= 1 ;i<=N;i++) scanf( " %I64d " ,& H[i]); for ( i= 1 ;i<=M;i++) scanf( " %I64d " ,& R[i]); i64 l =- 1 ,r=abs(H[ 1 ]-R[ 1 ])* 2 +abs(H[ 1 ]- R[M]),mid; while (l+ 1 < r) { mid =(l+r)>> 1 ; if (judge(mid)) r= mid; else l= mid; } printf( " %I64d\n " ,r); } return 0 ; }
?
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元
