zoukankan      html  css  js  c++  java
  • 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;
    }
    

      

    编译人生,运行世界!
  • 相关阅读:
    Pycharm中的加载多个项目
    Python中的条件选择和循环语句
    Python中的模块
    python在不同层级目录import模块的方法
    数据结构与算法分析:C语言描述(原书第2版 简体中文版!!!) PDF+源代码+习题答案
    数据结构和算法关系
    二叉树及二叉树的遍历
    栈及其应用
    基础知识- 算法复杂度
    Java 特定规则排序-LeetCode 179 Largest Number
  • 原文地址:https://www.cnblogs.com/Running-Time/p/4857810.html
Copyright © 2011-2022 走看看