现在的位置: 首页 > 综合 > 正文

Codeforces Round #291 (Div. 2)

2018年04月28日 ⁄ 综合 ⁄ 共 2732字 ⁄ 字号 评论关闭

A题:

A. Chewbaсca and Number
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Luke Skywalker gave Chewbacca an integer number x. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit t means
replacing it with digit 9 - t.

Help Chewbacca to transform the initial number x to the minimum possible positive number
by inverting some (possibly, zero) digits. The decimal representation of the final number shouldn't start with a zero.

Input

The first line contains a single integer x (1 ≤ x ≤ 1018) —
the number that Luke Skywalker gave to Chewbacca.

Output

Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes.

Sample test(s)
input
27
output
22
input
4545
output
4444

解题思路:

简单的贪心问题,题目说的是只要每位数字进行9-t与t的互换,使得最终换后的结果最小就可以了.

代码:

# include<cstdio>
# include<iostream>
# include<cstring>

using namespace std;

char s[20];

int main(void)
{
    cin>>s;
    int i = 0;
    while ( s[i] )
    {
        if ( i==0&&s[i]=='9')
        {
            i++;
            continue;
        }
       if ( s[i] >= '5' )
        {
            s[i] = '9'-s[i]+'0';
            i++;
            continue;
        }
        i++;
    }
    cout<<s<<endl;

    return 0;
}

B题:

B. Han Solo and Lazer Gun
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his
coordinates (x, y) on this plane.

Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0).
In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x0, y0).

Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.

The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.

Input

The first line contains three integers nx0 и y0 (1 ≤ n ≤ 1000 - 104 ≤ x0, y0 ≤ 104)
— the number of stormtroopers on the battle field and the coordinates of your gun.

Next n lines contain two integers each xiyi ( - 104 ≤ xi, yi ≤ 104)
— the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.

Output

Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.

Sample test(s)
input
4 0 0
1 1
2 2
2 0
-1 -1
output
2
input
2 1 2
1 1
1 0
output
1
Note

Explanation to the first and second samples from the statement, respectively:

解题思路:

这道题一看就是枚举k,然后只要统计不同的k就可以了,但是,让我学会 了用set写,先前一直没用set写过题,这道题算是第一个吧。。。

有个小坑就是要注意a-xx==0的情况,这里用fabs(a-xx)<1e-10来控制下精度,怕出SB数据。。来表示这种特殊的位置。

代码:

# include<cstdio>
# include<iostream>
# include<cmath>
# include<set>

using namespace std;

int main(void)
{
    int n;
    double xx,yy;
    while ( cin>>n>>xx>>yy )
    {
        int p  = 0;
        set<double>s;

        for ( int i = 0;i < n;i++ )
        {
            double a,b;
            cin>>a>>b;
            if ( fabs(a-xx)<1e-10 )
            {
                p = 1;
            }
            else
            {
                s.insert((b-yy)/(a-xx) );
            }
        }
        cout<<s.size()+p<<endl;

    }



    return 0;
}

C题:

解题思路:

D题:

抱歉!评论已关闭.