STL 2016.11.8

1、Codeforces 514B Han Solo and Lazer Gun

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <ctime>
#include <cctype>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pair;

const ll mod = 1e9 + 7;
const int INF = 0x7fffffff;

int n, x_0, y_0, x, y;
map<Pair, int> Map;

int main()
{
#ifdef __AiR_H
    freopen("in.txt", "r", stdin);
#endif // __AiR_H_
    scanf("%d %d %d", &n, &x_0, &y_0);
    int ans = 0;
    while (n--) {
        scanf("%d %d", &x, &y);
        int x_t = x - x_0, y_t = y - y_0;
        if (x_t != 0 && y_t != 0) {
            int gcd = __gcd(x_t, y_t);
            x_t /= gcd, y_t /= gcd;
        } else if (x_t == 0 && y_t != 0) {
            y_t = 1;
        } else if (x_t != 0 && y_t == 0) {
            x_t = 1;
        }
        if (Map[make_pair(x_t, y_t)] == 0) {
            Map[make_pair(x_t, y_t)] = 1;
            Map[make_pair(-x_t, -y_t)] = 1;
            ++ans;
        }
    }
    printf("%d\n", ans);
    return 0;
}

2、Codeforces 650A Watchmen

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <ctime>
#include <cctype>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pair;

const ll mod = 1e9 + 7;
const int INF = 0x7fffffff;

int n, x, y;
map<Pair, int> Map_pair;
map<int, int> Map_x, Map_y;

int main()
{
#ifdef __AiR_H
    freopen("in.txt", "r", stdin);
#endif // __AiR_H_
    scanf("%d", &n);
    ll cnt = 0;
    while (n--) {
        scanf("%d %d", &x, &y);
        ++Map_pair[make_pair(x, y)];
        ++Map_x[x], ++Map_y[y];
    }
    ll ans = 0;
    map<int, int>::iterator itr;
    for (itr = Map_x.begin(); itr != Map_x.end(); ++itr) {
        int t = itr->second;
        if (t > 1) {
            ans += (ll)t * (t - 1) / 2;
        }
    }
    for (itr = Map_y.begin(); itr != Map_y.end(); ++itr) {
        int t = itr->second;
        if (t > 1) {
            ans += (ll)t * (t - 1) / 2;
        }
    }
    map<Pair, int>::iterator itr_pair;
    for (itr_pair = Map_pair.begin(); itr_pair != Map_pair.end(); ++itr_pair) {
        int t = itr_pair->second;
        if (t > 1) {
            cnt += (ll)t * (t - 1) / 2;
        }
    }
    printf("%lld\n", ans - cnt);
    return 0;
}

3、Codeforces 158C Cd and pwd commands

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <ctime>
#include <cctype>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pair;

const ll mod = 1e9 + 7;
const int INF = 0x7fffffff;

string ans, cmd;
string dir;
int n;

int main()
{
#ifdef __AiR_H
    freopen("in.txt", "r", stdin);
#endif // __AiR_H_
    ans = "/";
    scanf("%d", &n);
    while (n--) {
        cin >> cmd;
        if (cmd == "pwd") {
            cout << ans << endl;
        } else {
            cin >> dir;
            dir += "/";
            int len = dir.length();
            cmd = "";
            if (dir[0] == '/') {
                ans = "/";
                for (int i = 1; i < len; ++i) {
                    if (dir[i] != '/') {
                        cmd += dir[i];
                    } else {
                        if (cmd == "..") {
                            if (ans != "/") {
                                int len_t = ans.length();
                                int d_len = 1;
                                for (int i = len_t - 2; ans[i] != '/'; --i) {
                                    ++d_len;
                                }
                                ans = ans.substr(0, len_t - d_len);
                            }
                        } else {
                            ans += cmd;
                        }
                        if (ans[ans.length() - 1] != '/') {
                            ans += "/";
                        }
                        cmd = "";
                    }
                }
            } else {
                for (int i = 0; i < len; ++i) {
                    if (dir[i] != '/') {
                        cmd += dir[i];
                    } else {
                        if (cmd == "..") {
                            if (ans != "/") {
                                int len_t = ans.length();
                                int d_len = 1;
                                for (int i = len_t - 2; ans[i] != '/'; --i) {
                                    ++d_len;
                                }
                                ans = ans.substr(0, len_t - d_len);
                            }
                        } else {
                            ans += cmd;
                        }
                        if (ans[ans.length() - 1] != '/') {
                            ans += "/";
                        }
                        cmd = "";
                    }
                }
            }
        }
    }
    return 0;
}

4、Codeforces 501B Misha and Changing Handles

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <ctime>
#include <cctype>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pair;

const ll mod = 1e9 + 7;
const int INF = 0x7fffffff;

map<string, string> Map;
int n;
string Old, New;

int main()
{
#ifdef __AiR_H
    freopen("in.txt", "r", stdin);
#endif // __AiR_H_
    scanf("%d", &n);
    while (n--) {
        cin >> Old >> New;
        if (!Map.count(Old)) {
            Map[Old] = Old;
        }
        Map[New] = Map[Old];
        Map.erase(Old);
    }
    int Size = Map.size();
    printf("%d\n", Size);
    map<string, string>::iterator itr;
    for (itr = Map.begin(); itr != Map.end(); ++itr) {
        cout << itr->second << " " << itr->first << endl;
    }
    return 0;
}

5、Codeforces 733D Kostya the Sculptor

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <ctime>
#include <cctype>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pair;

const int mod = 1e9 + 7;
const int INF = 0x7fffffff;
const int maxn = 1e5 + 10;

map<Pair, Pair> mp;
int n, x, y, z;

int main() {
#ifdef __AiR_H
    freopen("in.txt", "r", stdin);
#endif // __AiR_H_
    scanf("%d", &n);
    int Max = 0, t = 0, ans1 = 0, ans2 = 0;
    for (int i = 1; i <= n; ++i) {
        scanf("%d %d %d", &x, &y, &z);
        if (x > y) { swap(x, y); }
        if (x > z) { swap(x, z); }
        if (y > z) { swap(y, z); }
        if (x > Max) { Max = x, ans1 = i; ans2 = 0; }
        if (mp.count(make_pair(x, y))) {
            if (x > Max) { Max = x; ans1 = i; ans2 = mp[make_pair(x, y)].second; }
        }
        if (mp.count(make_pair(x, z))) {
            if (x > Max) { Max = x; ans1 = i; ans2 = mp[make_pair(x, z)].second; }
        }
        if (mp.count(make_pair(y, z))) {
            t = min(y, mp[make_pair(y, z)].first + x);
            if (t > Max) { Max = t; ans1 = i; ans2 = mp[make_pair(y, z)].second; }
        }
        if (!mp.count(make_pair(x, y)) || mp[make_pair(x, y)].first < z) {
            mp[make_pair(x, y)] = make_pair(z, i);
        }
        if (!mp.count(make_pair(x, z)) || mp[make_pair(x, z)].first < y) {
            mp[make_pair(x, z)] = make_pair(y, i);
        }
        if (!mp.count(make_pair(y, z)) || mp[make_pair(y, z)].first < x) {
            mp[make_pair(y, z)] = make_pair(x, i);
        }
    }
    if (ans2 == 0) {
        printf("1\n");
        printf("%d\n", ans1);
    } else {
        printf("2\n");
        printf("%d %d\n", ans1, ans2);
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值