Codeforces Round #231 (Div. 2)

好久没写日志,得狂补了,,太懒,虽然都是水题

昨晚打的一场,第一次自己做出了C题哭

394A:

A. Counting Sticks
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmetics from the start. And what is the best way to teach students add and subtract? — That's right, using counting sticks! An here's our new task:

An expression of counting sticks is an expression of type:

[ A sticks][sign +][ B sticks][sign =][ C sticks] (1 ≤ A, B, C).

Sign + consists of two crossed sticks: one vertical and one horizontal. Sign= consists of two horizontal sticks. The expression is arithmetically correct ifA + B = C.

We've got an expression that looks like A + B = C given by counting sticks. Our task is to shift at most one stick (or we can shift nothing) so that the expression became arithmetically correct. Note that we cannot remove the sticks from the expression, also we cannot shift the sticks from the signs+ and =.

We really aren't fabulous at arithmetics. Can you help us?

Input

The single line contains the initial expression. It is guaranteed that the expression looks likeA + B = C, where 1 ≤ A, B, C ≤ 100.

Output

If there isn't a way to shift the stick so the expression becomes correct, print on a single line "Impossible" (without the quotes). If there is a way, print the resulting expression. Follow the format of the output from the test samples. Don't print extra space characters.

If there are multiple correct answers, print any of them. For clarifications, you are recommended to see the test samples.

Sample test(s)
Input
||+|=|||||
Output
|||+|=||||
Input
|||||+||=||
Output
Impossible
Input
|+|=||||||
Output
Impossible
Input
||||+||=||||||
Output
||||+||=||||||
Note

In the first sample we can shift stick from the third group of sticks to the first one.

In the second sample we cannot shift vertical stick from + sign to the second group of sticks. So we cannot make a - sign.

There is no answer in the third sample because we cannot remove sticks from the expression.

In the forth sample the initial expression is already arithmetically correct and that is why we don't have to shift sticks.

我会说题意没看懂么,。。。论看不懂题意AC的科学性,,,

就是那些棍子,问最多移动一个是否可以使等式成立,,这个题有个隐含条件,,就是移走棍子后不能变为0,,开始没注意被hack了哭

代码如下:

 

/**
 * @author neko01
 */
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <cstring>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long LL;
#define INF 0x7fffffff
const double pi=acos(-1.0);
const double eqs=1e-10;
char s[1001];
int main()
{
    int x,y,z,sum=0;
    scanf("%s",s);
    for(int i=0;s[i]!='\0';i++)
    {
        if(s[i]=='|')
            sum++;
        if(s[i]=='+')
        {
            x=sum;
            sum=0;
        }
        if(s[i]=='=')
        {
            y=sum;
            sum=0;
        }
    }
    z=sum;
    if (x>1&&x-1+y==z+1)
    {
        x--;
        z++;
    }
    else if (y>1&&x+y-1==z+1)
    {
        y--;
        z++;
    }
    else if (z>1&&x+1+y==z-1)
    {
        x++;
        z--;
    }
    if (x + y == z)
    {
        while (x--) printf("|"); printf("+");
        while (y--) printf("|"); printf("=");
        while (z--) printf("|"); printf("\n");
    }
    else
    {
        printf("Impossible\n");
    }
    return 0;
}

394B:

B. Very Beautiful Number
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Teacher thinks that we make a lot of progress. Now we are even allowed to use decimal notation instead of counting sticks. After the test the teacher promised to show us a "very beautiful number". But the problem is, he's left his paper with the number in the teachers' office.

The teacher remembers that the "very beautiful number" was strictly positive, didn't contain any leading zeroes, had the length of exactly p decimal digits, and if we move the last digit of the number to the beginning, it grows exactly x times. Besides, the teacher is sure that among all such numbers the "very beautiful number" is minimal possible.

The teachers' office isn't near and the teacher isn't young. But we've passed the test and we deserved the right to see the "very beautiful number". Help to restore the justice, find the "very beautiful number" for us!

Input

The single line contains integers p, x (1 ≤ p ≤ 106, 1 ≤ x ≤ 9).

Output

If the teacher's made a mistake and such number doesn't exist, then print on a single line "Impossible" (without the quotes). Otherwise, print the "very beautiful number" without leading zeroes.

Sample test(s)
Input
6 5
Output
142857
Input
1 2
Output
Impossible
Input
6 4
Output
102564

好吧,,题意竟然看懂了,就不多说,,

开始真的感觉毫无思路,直接暴力找每个数肯定不科学,最后看见群里众巨讨论说枚举最后一位,开始还纳闷,最后用样例比划了下还真是,,比赛时没赶敲,事后补了下,,整个过程就和个位数乘以一个大数一样,需要注意的是最后判断是否满足的条件,,看来姿势一定要对,。,。

代码:

/**
 * @author neko01
 */
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <cstring>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long LL;
#define INF 100000000
const double pi=acos(-1.0);
const double eqs=1e-10;
int ans[1000005];
int main()
{
    int p,x,flag=0;
    scanf("%d%d",&p,&x);
    for(int i=1;i<10;i++)
    {
        ans[1]=i;
        int mod=0;
        for(int j=2;j<=p;j++)
        {
            int t=ans[j-1]*x+mod;
            ans[j]=t%10;;
            mod=t/10;;
        }
        if((ans[p]*x)/10==0&&(ans[p]*x)%10+mod==i&&ans[p]!=0)
        {
            flag=1;
            break;
        }
    }
    if(!flag)
    {
        printf("Impossible\n");
    }
    else
    {
        for(int i=p;i>=1;i--)
            printf("%d",ans[i]);
        printf("\n");
    }
    return 0;
}

394C

C. Dominoes
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

During the break, we decided to relax and play dominoes. Our box with Domino was empty, so we decided to borrow the teacher's dominoes.

The teacher responded instantly at our request. He put nm dominoes on the table as an n × 2m rectangle so that each of the n rows contained m dominoes arranged horizontally. Each half of each domino contained number (0 or 1).

We were taken aback, and the teacher smiled and said: "Consider some arrangement of dominoes in an n × 2m matrix. Let's count for each column of the matrix the sum of numbers in this column. Then among all such sums find the maximum one. Can you rearrange the dominoes in the matrix in such a way that the maximum sum will be minimum possible? Note that it is prohibited to change the orientation of the dominoes, they all need to stay horizontal, nevertheless dominoes are allowed to rotate by 180 degrees. As a reward I will give you all my dominoes".

We got even more taken aback. And while we are wondering what was going on, help us make an optimal matrix of dominoes.

Input

The first line contains integers n, m (1 ≤ n, m ≤ 103).

In the next lines there is a description of the teachers' matrix. Each of next n lines contains m dominoes. The description of one domino is two integers (0 or 1), written without a space — the digits on the left and right half of the domino.

Output

Print the resulting matrix of dominoes in the format: n lines, each of them contains m space-separated dominoes.

If there are multiple optimal solutions, print any of them.

Sample test(s)
Input
2 3
01 11 00
00 01 11
Output
11 11 10
00 00 01
Input
4 1
11
10
01
00
Output
11
10
01
00

yy的意思,n*m的那些牌随便排列,10可以等价成01,求一种排列使得每一竖列的最大和最小。

很感动在比赛快结束的时候过了,,大哭,不过逗比的数组开小一次RE,。,。

看见有人说先排10,在那下面排01,最后排11,00,,其实我觉得先排11也可以,因为11肯定不影响,这个题主要是10和01尽可能多的上下同一列排

代码如下:

 

/**
 * @author neko01
 */
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <cstring>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long LL;
#define INF 100000000
const double pi=acos(-1.0);
const double eqs=1e-10;
int a[1050][1050];
char s[5];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    int b=0,c=0,d=0,e=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            scanf("%s",s);
            if(s[0]=='0'&&s[1]=='0')
                b++;
            if(s[0]=='0'&&s[1]=='1')
                c++;
            if(s[0]=='1'&&s[1]=='0')
                c++;
            if(s[0]=='1'&&s[1]=='1')
                e++;
        }
    }
    int cc=c/2;
    c=c-cc;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(e)
            {
                a[i][j]=3;
                e--;
            }
            else if(c)
            {
                a[i][j]=1;
                c--;
            }
            else if(cc&&a[i-1][j]==1)
            {
                a[i][j]=2;
                cc--;
            }
            else if(b)
            {
                a[i][j]=0;
                b--;
            }
            else if(cc)
            {
                a[i][j]=2;
                d--;
            }
            if(a[i][j]==0)
                printf("00 ");
            else if(a[i][j]==1)
                printf("01 ");
            else if(a[i][j]==2)
                printf("10 ");
            else
                printf("11 ");
        }
        printf("\n");
    }
    return 0;
}


过两天补一下D,,这两天浪费时间浪费生命真可怕,,,。。哭

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值