• Codeforces Round #323 (Div. 2)


    被进爷坑了,第二天的比赛改到了12点

    水 A - Asphalting Roads

    /************************************************
    * Author        :Running_Time
    * Created Time  :2015/10/3 星期六 21:53:09
    * File Name     :A.cpp
     ************************************************/
    
    #include <cstdio>
    #include <algorithm>
    #include <iostream>
    #include <sstream>
    #include <cstring>
    #include <cmath>
    #include <string>
    #include <vector>
    #include <queue>
    #include <deque>
    #include <stack>
    #include <list>
    #include <map>
    #include <set>
    #include <bitset>
    #include <cstdlib>
    #include <ctime>
    using namespace std;
    
    #define lson l, mid, rt << 1
    #define rson mid + 1, r, rt << 1 | 1
    typedef long long ll;
    const int N = 55;
    const int INF = 0x3f3f3f3f;
    const int MOD = 1e9 + 7;
    const double EPS = 1e-8;
    bool r[N], c[N];
    
    int main(void)    {
    	memset (r, false, sizeof (r));
    	memset (c, false, sizeof (c));
    	int n;	scanf ("%d", &n);
    	vector<int> ans;
        n = n * n;
    	for (int x, y, i=1; i<=n; ++i)	{
    		scanf ("%d%d", &x, &y);
    		if (!r[x] && !c[y])	{
    			r[x] = c[y] = true;
    			ans.push_back (i);
    		}
    	}
    	for (int i=0; i<ans.size (); ++i)	{
    		printf ("%d%c", ans[i], (i == ans.size () - 1) ? '
    ' : ' ');
    	}
    
        return 0;
    }
    

    水 B - Robot's Task

    /************************************************
    * Author        :Running_Time
    * Created Time  :2015/10/3 星期六 21:53:24
    * File Name     :B.cpp
     ************************************************/
    
    #include <cstdio>
    #include <algorithm>
    #include <iostream>
    #include <sstream>
    #include <cstring>
    #include <cmath>
    #include <string>
    #include <vector>
    #include <queue>
    #include <deque>
    #include <stack>
    #include <list>
    #include <map>
    #include <set>
    #include <bitset>
    #include <cstdlib>
    #include <ctime>
    using namespace std;
    
    #define lson l, mid, rt << 1
    #define rson mid + 1, r, rt << 1 | 1
    typedef long long ll;
    const int N = 1e3 + 10;
    const int INF = 0x3f3f3f3f;
    const int MOD = 1e9 + 7;
    const double EPS = 1e-8;
    int a[N];
    
    int main(void)    {
        int n;  scanf ("%d", &n);
        for (int i=1; i<=n; ++i)    {
            scanf ("%d", &a[i]);
        }
        int ans = 0, d = 1, m = 0, p = 0;
        bool flag = false;
        while (true)   {
            if (d == 1) {
                for (int i=p+1; i<=n; ++i)    {
                    if (m >= a[i])  {
                        a[i] = INF;
                        m++;    p = i;
                        flag = true;
                    }
                }
                if (m == n) break;
                d ^= 1; ans++;
            }
            else    {
                for (int i=p-1; i>=1; --i)    {
                    if (m >= a[i])  {
                        a[i] = INF;
                        m++;    p = i;
                        flag = true;
                    }
                }
                if (m == n) break;
                d ^= 1; ans++;
            }
        }
        printf ("%d
    ", ans);
    
        return 0;
    }
    

    贪心 C - GCD Table

    题意:给了一张GCD表,问原来的求GCD的那些数

    分析:从大到小找,最大的数和其他的数的GCD都不大于它,每次找到一个就能把它和已知的答案的GCD给删除,map+暴力就可以了

    /************************************************
    * Author        :Running_Time
    * Created Time  :2015/10/3 星期六 21:53:35
    * File Name     :C.cpp
     ************************************************/
    #include <cstdio>
    #include <algorithm>
    #include <iostream>
    #include <sstream>
    #include <cstring>
    #include <cmath>
    #include <string>
    #include <vector>
    #include <queue>
    #include <deque>
    #include <stack>
    #include <list>
    #include <map>
    #include <set>
    #include <bitset>
    #include <cstdlib>
    #include <ctime>
    using namespace std;
    
    #define lson l, mid, rt << 1
    #define rson mid + 1, r, rt << 1 | 1
    typedef long long ll;
    const int N = 5e2 + 10;
    const int INF = 0x3f3f3f3f;
    const int MOD = 1e9 + 7;
    const double EPS = 1e-8;
    int a[N*N];
    int ans[N];
    map<int, int> cnt;
    
    int GCD(int a, int b)   {
        return b ? GCD (b, a % b) : a;
    }
    
    int main(void)    {
        int n;  scanf ("%d", &n);
        int m = n;
        n = n * n;
        for (int i=1; i<=n; ++i)    {
            scanf ("%d", &a[i]);
            cnt[-a[i]]++;
        }
        int pos = m;
        map<int, int>::iterator it;
        for (it=cnt.begin (); it!=cnt.end (); ++it) {
            int x = -it -> first;
            while (it -> second)    {
                ans[pos] = x;
                --it -> second;
                for (int i=pos+1; i<=m; ++i)    {
                    cnt[-GCD (ans[pos], ans[i])] -= 2;
                }
                pos--;
            }
        }
    
        for (int i=1; i<=m; ++i)   {
            printf ("%d%c", ans[i], (i == m) ? '
    ' : ' ');
        }
    
        return 0;
    }
    

      

    编译人生,运行世界!
  • 相关阅读:
    10 行Python代码实现批量压缩图片500 张,面试必学
    用Python邮件发送,新手必学
    用Python监控男女朋友每天都在看哪些网站?这招绝了
    不踩坑的Python爬虫:如何在一个月内学会爬取大规模数据?新手必学
    用Python做一个520表白神器,值得收藏
    微分不等式
    零点问题
    2019英语一 Text4分析
    A1065. A+B and C(64bit)
    A1046. Shortest Distance
  • 原文地址:https://www.cnblogs.com/Running-Time/p/4857810.html
Copyright © 2020-2023  润新知