Codeforces Round #346 (Div. 2) ABCDE

题目:http://codeforces.com/contest/659/problems
A:

#include <iostream>
#include <string>

using namespace std;

int n, a, b;

int main()
{
    while (cin >> n >> a >> b)
    {
        int ans;
        ans = (a + b + n * 1000) % (n);
        if (ans == 0) ans = n;
        cout << ans << endl;
    }
    return 0;
}

B:

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

vector <pair<int, string>> a[10010];


int n, m;
int main()
{
    while (cin >> n >> m)
    {

        string tmp;
        int num, val;
        for (int i = 1;i <= n;i++)
        {
            cin >> tmp >> num >> val;
            num--;
            val = -val;
            a[num].push_back(make_pair(val, tmp));
        }


        for (int i = 0;i < m;i++)
        {

            sort(a[i].begin(), a[i].end());
            if (a[i].size() > 2 && a[i][1].first == a[i][2].first) 
                puts("?");
            else
                cout << a[i][0].second <<" "<< a[i][1].second << endl;
        }
    }
    return 0;
}

C:

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

int n, m;
set<int> S;
vector<int> ans;

int main()
{
    while (cin >> n >> m)
    {
        ans.clear();
        S.clear();
        set<int>::iterator pos;
        vector<int>::iterator it;

        int tmp;
        for (int i = 1;i <= n;i++)
        {
            cin >> tmp;
            S.insert(tmp);
        }

        tmp = 1;
        while (m)
        {
            if (m < tmp) break;
            if (S.count(tmp) == 0)
            {
                m -= tmp;
                ans.push_back(tmp);
                S.insert(tmp);
                tmp++;
            }
            else
                tmp++;
        }
        cout << ans.size() << endl;
        for (it = ans.begin();it != ans.end();it++)
            cout << *it << " ";
        cout << endl;
    }
    return 0;
}

D:

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

int n;

struct
{
    int x, y;
}a[1010];

int main()
{
    while (scanf("%d", &n) != EOF)
    {
        memset(b, 0, sizeof(b));

        for (int i = 0;i <= n;i++)
        {
            scanf("%d %d", &a[i].x, &a[i].y);
        }

        int ans = 0;
        for (int i = 0;i < n;i++)
        {
            int t1 = i + 1;
            int t2 = i + 2;
            if (t2 == n + 1) t2 = 0;

            if (a[i].x < a[i + 1].x && a[i].y == a[i + 1].y)//右
            {
                if (a[t1].x == a[t2].x && a[t1].y < a[t2].y)//↑
                    ans++;
            }
            else if (a[i].x > a[i + 1].x && a[i].y == a[i + 1].y)//左
            {
                if (a[t1].x == a[t2].x && a[t1].y > a[t2].y)//下
                    ans++;
            }
            else if (a[i].x == a[i + 1].x && a[i].y < a[i + 1].y)//上
            {
                if (a[t1].x > a[t2].x && a[t1].y == a[t2].y)//左
                    ans++;
            }
            else if (a[i].x == a[i + 1].x && a[i].y > a[i + 1].y)//下
            {
                if (a[t1].x < a[t2].x && a[t1].y == a[t2].y)//右
                    ans++;
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}

E:

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

const int MAXN = 200010;

vector<int> g[MAXN];

int n, m, nnode, nedge;
int vis[MAXN];

void dfs(int u)
{
    vis[u] = 1;
    nnode++;
    for (int i = 0;i < g[u].size();i++)
    {
        int v = g[u][i];
        nedge++;
        if (!vis[v])
            dfs(v);
    }

}

int main()
{
    while (scanf("%d %d", &n, &m) != EOF)
    {
        memset(vis, 0, sizeof vis);
        for (int i = 0;i <= n;i++)
            g[i].clear();
        int u, v;
        for (int i = 1;i <= m;i++)
        {
            scanf("%d %d", &u, &v);
            g[u].push_back(v);
            g[v].push_back(u);
        }

        int ans = 0;
        for (int i = 1;i <= n;i++)
        {
            if (!vis[i])
            {
                nnode = nedge = 0;
                dfs(i);
                if (nedge / 2 == nnode - 1)
                    ans++;
            }
        }

        printf("%d\n", ans);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值