Codeforces#200 div.2

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 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. Thenn lines follow. The
i-th line (1?≤?i?≤?n) contains either characters "01", if Mike put thei-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 Input

Input

6
10
10
10
01
10
10

Output

3

Input

4
01
01
10
10

Output

2

Hint

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.

/***************************************************************************************
  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,b) (a)>(b)?(a):(b)
#define MIN(a,b) (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 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 formone 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.

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 are 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 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.

/***************************************************************************************
  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,b) (a)>(b)?(a):(b)
#define MIN(a,b) (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<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 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:

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

Output

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 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 resistor consecutively. Then, we get an element with resistance.
We cannot make this element using two 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,b) (a)>(b)?(a):(b)
#define MIN(a,b) (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 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 andwithout
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.

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

/*************************************************************************
     File Name: 1.cpp
     ID: Liusiyu
     PROG:
     LANG: C++
     Mail: [email protected]
     Created Time: 2016年07月12日 星期二 09时33分16秒
************************************************************************/
#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,b) (a)>(b)?(a):(b);
#define MIN(a,b) (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=0x3f3f3f3f;
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;
 }
}
时间: 2024-11-09 00:16:50

Codeforces#200 div.2的相关文章

Codeforces #200(div.2) 模拟练习赛

A题: 题意:一行磁铁,同性相斥,找到这行磁铁可以分为多少块 思路:边读边计算,读到和上一次不一样的就加1(第一组数据特判) 手速题然而我没有把思路理清楚再写,比队友满了太多=_+. 代码: #include <set> #include <map> #include <cmath> #include <stack> #include <queue> #include <string> #include <vector>

Codeforces #258 Div.2 E Devu and Flowers

大致题意: 从n个盒子里面取出s多花,每个盒子里面的花都相同,并且每个盒子里面花的多数为f[i],求取法总数. 解题思路: 我们知道如果n个盒子里面花的数量无限,那么取法总数为:C(s+n-1, n-1) = C(s+n-1, s). 可以将问题抽象成:x1+x2+...+xn = s, 其中0<=xi <= f[i],求满足条件的解的个数. 两种方法可以解决这个问题: 方法一:这个问题的解可以等价于:mul = (1+x+x^2+...+x^f[1])*(1+x+x^2+...+x^f[2]

Codeforces #259 Div.2

A. Little Pony and Crystal Mine 模拟题. 用矩阵直接构造或者直接根据关系输出 B. Little Pony and Sort by Shift 模拟题. 通过提供的操作得到的序列只能是两段递增或者整个序列递增. 那么可以求得第一段递增序列长度为0-p 如果整个序列是递增,即 p= n-1 那么操作次数就是0. 否则,假设是两段递增,把原始的序列恢复出来,设当前序列是AB,那么A就是0-p BA = (A'B')', '表示对序列进行翻转, 如果BA是有序的,那么需

Codeforces #250 (Div. 2) C.The Child and Toy

之前一直想着建图...遍历 可是推例子都不正确 后来看数据好像看出了点规律 就抱着试一试的心态水了一下 就....过了..... 后来想想我的思路还是对的 先抽象当前仅仅有两个点相连 想要拆分耗费最小,肯定拆相应权值较小的 在这个基础上考虑问题就能够了 代码例如以下: #include <cstdio> #include <iostream> #include <algorithm> #define MAXN 10010 #define ll long long usi

Codeforces #256 Div.2

B. Suffix Structure 1. 先判断s去掉一些元素是否能构成t,如果可以就是automaton 判断的方法也很简单,two pointer,相同元素同时++,不相同s的指针++,如果t能全找到,那么s能够去掉元素构成t. bool f(string s, string t) { int i = 0, j = 0; while (i < s.size() && j < t.size()) { if (s[i] == t[j]) { i++; j++; } else

Codeforces Round #200 (Div. 2) (ABCDE题解)

比赛链接:http://codeforces.com/contest/344 A. Magnets time limit per test:1 second memory limit per test:256 megabytes Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets inst

Codeforces Round #200 (Div. 2)

打算从200开始刷到现在的  谢谢思路就好了 A:和上一次输入不一样就ans++ B:每次找两个最大的匹配一些 C:假设现在电阻为x/y  串连时变为(x+y)/y  并联时变成 y/(x+y)  可见同样消耗1个电阻  形成的新值互为倒数  这个结论允许我们将电阻值的分子分母随意换(不影响使用电阻总数)  明显电阻值>1的时候  我们采取串联一定整数的电阻  因此可以得出方法  电阻>1时串联  <1时倒过来  又>1了  不停做--  这个过程很类似辗转相除 D:用栈模拟  字

343D/Codeforces Round #200 (Div. 1) D. Water Tree dfs序+数据结构

D. Water Tree Mad scientist Mike has constructed a rooted tree, which consists of n vertices. Each vertex is a reservoir which can be either empty or filled with water. The vertices of the tree are numbered from 1 to n with the root at vertex 1. For

Codeforces Round #200 (Div. 1) D. Water Tree(dfs序加线段树)

思路: dfs序其实是很水的东西.  和树链剖分一样, 都是对树链的hash. 该题做法是:每次对子树全部赋值为1,对一个点赋值为0,查询子树最小值. 该题需要注意的是:当我们对一棵子树全都赋值为1的时候, 我们要查询一下赋值前子树最小值是不是0, 如果是的话, 要让该子树父节点变成0, 否则变0的信息会丢失. 细节参见代码: #include <cstdio> #include <cstring> #include <algorithm> #include <i