codeforces#200 Div.2

Source: Internet
Author: User
Tags bitset cmath

Description

Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn ' t need dominoes, THOUGH:HE uses rectangular magnets instead. Each magnet has a poles, positive (a "plus") and negative (a "minus"). If the magnets is put together at a close distance, then the like Poles would repel each other and the opposite Poles would Attract each of the 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 what Mike puts the magnet on the table, it's either attracted to the previous one (forming a group of MULTIPL e magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous O NE). We assume 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. Thenn lines follow. Thei-th line (1?≤? I? ≤? n) contains either characters "", if Mike put thei-th magnet in the "Plus-minus" p Osition, or characters "ten", if Mike put the magnet in the "minus-plus" position.

Output

The the single line of the output print the number of groups of magnets.

Sample Input

Input
6101010011010
Output
3
Input
401011010
Output
2

Hint

The first testcase corresponds to the figure. The TestCase has three groups consisting of three, one and both magnets.

The second testcase has a groups, each consisting of the magnets.

/*************************************************************************************** Question:http://                                                                   acm.hust.edu.cn/vjudge/contest/view.action?cid=121431#problem/a date:2016.07.10 Author:Liusiyu  /  \  \  \  |  |  |                                                              | |                                         *    \  \  \  \  \  \                                                         __\--|__ **   /  /  /  /  /  /  II=======OOOOO[/★02 __| * *//|  |  |                                                       |  _\______|/--* *   /  |  |  |  |                                                      |  /_____________|  /  |  |  |  |  |                                                      | \ ⊙/****************************************************************************************/#include <iostream> #include <cstdio> #include <queue> #include <cstring> #include <cstdlib>#include <queue> #include <stack> #include <cmath> #include <map> #include <set> #include <algorithm> #include <cctype> #include <vector> #include <ctime> #include <list> #include <deque> #include <bitset> #define MEM (a,x) memset (A,x,sizeof (a)), #define Meminf (a) memset (A,0x3f,sizeof (A ); #define MAX (A, a) (a) > (b)? (a):(B) #define MIN (a) (a) < (b)? (a):(B) #define FL (s,n,a) Fill (s,s+n,a), #define MAPIT (A, b) map<a,b>::iterator it; #define VECIT (type) vector< Type>::iterator it; #define Setit (type) Set<type>::iterator it;using namespace Std;typedef long Long ll;const    int maxn=1005;//const int Minn=;//const int Inf=0x3f3f3f3f;int main () {int N;    int sum;    Char a[10],b[10];        while (scanf ("%d", &n)!=eof) {scanf ("%s", a);        sum=0;            for (int i=1;i<n;i++) {scanf ("%s", b);            if (b[0]==a[1]) sum++;            A[0]=B[0];        A[1]=B[1]; }    } Cout<<sum+1<<endl;} 

Mad scientist Mike is busy carrying out experiments in chemistry. Today He'll attempt to join three atoms into one molecule.

A molecule consists of atoms, with some pairs of atoms connected by atomic bonds. Each atom have a valence number-the number of bonds the atom must form with other atoms. An atom can form oneor 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 is 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 this it is impossible.

Input

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.

Output

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 is multiple solutions, output any of them. If There is no solution, print "impossible" (without the quotes).

Sample Input

Input
1 1 2
Output
0 1 1
Input
3 4 5
Output
1 3 2
Input
4 1 1
Output
Impossible

Hint

The first sample corresponds to the first figure. There is 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 a atom cannot form bonds with itself.

The configuration in the fourth are impossible as each atom must has at least one atomic bond.

/*************************************************************************************** Question:http://                                                                   Acm.hust.edu.cn/vjudge/contest/view.action?cid=121431#problem/b date:2016.07.10 Author:Liusiyu  /  \  \  \  |  |  |                                                              | |                                         *    \  \  \  \  \  \                                                         __\--|__ **   /  /  /  /  /  /  II=======OOOOO[/★02 __| * *//|  |  |                                                       |  _\______|/--* *   /  |  |  |  |                                                      |  /_____________|  /  |  |  |  |  |                                                      | \ ⊙/****************************************************************************************/#include <iostream> #include <cstdio> #include <queue> #include <cstring> #include <cstdlib>#include <queue> #include <stack> #include <cmath> #include <map> #include <set> #include <algorithm> #include <cctype> #include <vector> #include <ctime> #include <list> #include <deque> #include <bitset> #define MEM (a,x) memset (A,x,sizeof (a)), #define Meminf (a) memset (A,0x3f,sizeof (A ); #define MAX (A, a) (a) > (b)? (a):(B) #define MIN (a) (a) < (b)? (a):(B) #define FL (s,n,a) Fill (s,s+n,a), #define MAPIT (A, b) map<a,b>::iterator it; #define VECIT (type) vector< Type>::iterator it; #define Setit (type) Set<type>::iterator it;using namespace Std;typedef long Long ll;const    int maxn=1005;//const int Minn=;//const int Inf=0x3f3f3f3f;int main () {int a,b,c,x,y,z;        while (scanf ("%d%d%d", &a,&b,&c)!=eof) {x=a+b-c;        Y=b-a+c; if (x%2!=0| | y%2!=0| |        y<0) printf ("Impossible");            else {z=2*c-y;            X=2*a-z; if (x<0| |                Z&LT;0)printf ("impossible");        else printf ("%d%d%d\n", X/2,Y/2,Z/2); }    }}


Description

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 have was lots of identical resistors with unit resistance R0?=?1. Elements with other resistance can is constructed from these resistors. In this problem, we'll consider the following as elements:

    1. one resistor;
    2. An element and a resistor plugged in sequence;
    3. An element and a 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 caseRe 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.

Input

The single input line contains the space-separated integers a and b (1?≤? A,? b. ≤?10). It is guaranteed, the fraction is irreducible. It is guaranteed this a solution always exists.

Output

Print a single number-the answer to the problem.

%lld specifier to read or write 64-bit integers inс++. It is recommended to use thecin,cout streams or the%i64d specifier.

Sample Input

Input
1 1
Output
1
Input
3 2
Output
3
Input
199 200
Output
200

Hint

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 resis Tor consecutively. Then, we get a element with resistance. We cannot make this element using the resistors.

/*************************************************************************************** Question:http://                                                                   Acm.hust.edu.cn/vjudge/contest/view.action?cid=121431#problem/b date:2016.07.10 Author:Liusiyu  /  \  \  \  |  |  |                                                              | |                                         *    \  \  \  \  \  \                                                         __\--|__ **   /  /  /  /  /  /  II=======OOOOO[/★02 __| * *//|  |  |                                                       |  _\______|/--* *   /  |  |  |  |                                                      |  /_____________|  /  |  |  |  |  |                                                      | \ ⊙/****************************************************************************************/#include <iostream> #include <cstdio> #include <queue> #include <cstring> #include <cstdlib>#include <queue> #include <stack> #include <cmath> #include <map> #include <set> #include <algorithm> #include <cctype> #include <vector> #include <ctime> #include <list> #include <deque> #include <bitset> #define MEM (a,x) memset (A,x,sizeof (a)), #define Meminf (a) memset (A,0x3f,sizeof (A ); #define MAX (A, a) (a) > (b)? (a):(B) #define MIN (a) (a) < (b)? (a):(B) #define FL (s,n,a) Fill (s,s+n,a), #define MAPIT (A, b) map<a,b>::iterator it; #define VECIT (type) vector< Type>::iterator it; #define Setit (type) Set<type>::iterator it;using namespace Std;typedef long Long ll;const int maxn=1005;//const int Minn=;//const int inf=0x3f3f3f3f;ll sum=0;void deal (ll A,ll b) {if (a>b) {Sum+=a        /b;    A%=b;    } if (a==1) {Sum+=b;return;        } else {sum+=b/a;        if (b%a==0) return;    Deal (B%A,A);    }}int Main () {ll A, B;    scanf ("%i64d%i64d", &a,&b); cout<< "a=" <<a<< "b=" <<b<<endl;        if (a%b==0) {printf ("%i64d\n", A/b);    return 0;    } deal (A, b); printf ("%i64d\n", sum);}


Description

Mad scientist Mike have just finished constructing a new device to search for extraterrestrial intelligence! He is in such a hurry to launch it's the first time that he plugged in the power wires without giving it a proper glanc E and started experimenting right away. After a while Mike observed, the wires ended up entangled and now has to be untangled again.

The device is powered by and wires "plus" and "minus". The wires run along the floor is from the wall (the "on" to the device). Both The wall and the device have both contacts in them on the same level, into which the wires is plugged in some order. The wires is considered entangled if there is one or more places where one wire runs above the other one. For example, the picture below have four such places (top view):

Mike knows the sequence in which and the wires run above each other. Mike also noticed that on the left side, the ' plus ' wire was always plugged to the top contact (as seen on the picture). He would like to untangle the wires without unplugging them andwithout moving the device. Determine if it is possible to do. A wire can is freely moved and stretched on the floor, but cannot is cut.

To understand the problem better, read the notes to the test samples.

Input

The single line of the input contains a sequence of characters "+" and "-" of lengthn (1?≤? n? ≤?100000). Thei-th (1?≤? I? ≤? n) position of the sequence contains the character "+", if on theI-th step from the Wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise.

Output

Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) I f The wires cannot be untangled.

Sample Input

Input
-++-
Output
Yes
Input
+-
Output
No
Input
++
Output
Yes
Input
-
Output
No

Hint

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 ' crosses in the ', and then Draw it under the "minus" wire, eliminating also the remaining.

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 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:

/************************************************************************* File name:1.cpp Id:liusiyu PROG: lang:c++ Mail: [email protected] Created time:2016 July 12 Tuesday 09:33 16 seconds ***************************** /#include <cstdio> #include <cstring> #include <algorithm > #include <iostream> #include <cmath> #include <ctime> #include <stack> #include <queue > #include <set> #include <bitset> #include <deque> #include <vector> #include <map># Include <list> #include <cstdlib> #include <cassert> #include <functional> #include <iomanip > #include <utility> #include <complex> #include <numeric> #define MEM (a,x) memset (A,x,sizeof (a)); #define Meminf (a) memset (A,0x3f,sizeof (a)); #define MAX (a) (a) > (b)? (a):(B); #define MIN (a) (a) < (b)? (a):(B) #define APS (a) (a) >0? (a):-(a) #define FL (s,n,a) Fill (s,s+n,a); #define MAPIT (A, b) map<a,b>::iterator it; #define VECIT (type) vector<type>::iterator it; #define Setit (type) set< Type>::iterator it;using namespace Std;typedef long long ll;const int maxn=1e5+10;//const int Minn=;const int INF=0X3F3  F3f3f;int Main () {char A[MAXN]; Char S[MAXN];  while (scanf ("%s", a)!=eof) {int Len=strlen (a);  int flag=0; for (int i=0;i<len;i++) {if (!flag| |      S[flag]!=a[i]) {flag++;    S[flag]=a[i];  } else flag--;    } if (!flag) cout<< "Yes" <<endl; else cout<< "No" <<endl; }}


codeforces#200 Div.2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.