CodeForces #291 div.2 题解

A题:

题意:给出一个数字,其中每一位n可以转化为9-n,通过一定转化,使得得到的数字最小

思路:判断每一位,取min(n,9-n)即可

注意点:第一位不能为0。

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <deque>
#include <list>
#include <cctype>
#include <algorithm>
#include <climits>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#define ll long long
#define ull unsigned long long
#define all(x) (x).begin(), (x).end()
#define clr(a, v) memset( a , v , sizeof(a) )
#define pb push_back
#define mp make_pair
#define read(f) freopen(f, "r", stdin)
#define write(f) freopen(f, "w", stdout)
using namespace std;

int main()
{
    ios::sync_with_stdio( false );
    string str;
    while ( cin >> str ){
        if ( str[0] != '9' ){
            int num = str[0] - '0';
            num = min ( num,  9 - num );
            str[0] = num + '0';
        }
        for ( int i = 1; i < str.size(); i ++ ){
            int num = str[i] - '0';
            num = min ( num, 9 - num );
            str[i] = num + '0';
        }
        cout << str<< endl;
    }
    return 0;
}

B题:

题意:第一行给出三个数字,第一个是目标个数n,第二三个数是初始坐标(x,y),下面有n行,每行代表一个目标坐标(xt,yt),求最少要多少条直线能将所有目标与初始坐标相连、

思路:判断每一个点与初始点之间的斜率,维护一个set即可。

注意点:斜率用分数形式表示,小数形式需要1e-10的精度。

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <deque>
#include <list>
#include <cctype>
#include <algorithm>
#include <climits>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#define ll long long
#define ull unsigned long long
#define all(x) (x).begin(), (x).end()
#define clr(a, v) memset( a , v , sizeof(a) )
#define pb push_back
#define read(f) freopen(f, "r", stdin)
#define write(f) freopen(f, "w", stdout)
using namespace std;

const double eps = 1e-10;

bool cmp ( double a, double b )
{
    if ( a - b < eps && a - b > -eps ){
        return 1;
    }
    return 0;
}
int main()
{
    ios::sync_with_stdio( false );
    int n;
    double x, y;
    double a, b;
    while ( cin >> n >> x >> y ){
        vector<double> num;
        num.clear();
        bool flag;
        for ( int i = 0; i < n; i ++ ){
            cin >> a >> b;
            flag = true;
            double tmp;
            if ( cmp ( b, y ) )
                tmp = 0.0;
            else
                tmp = ( a - x ) / ( b - y );
            if ( cmp ( a, x ) )
                tmp = 1000000000.0;
            for ( int j = 0; j < num.size(); j ++ ){
                if ( cmp ( tmp, num[j] ) ){
                    flag = false;
                    break;
                }
            }
            if ( flag ) {
                num.pb ( tmp );
            }
        }
        cout << num.size() << endl;
    }
    return 0;
}

(未完待续)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值