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) ? ‘\n‘ : ‘ ‘);
	}

    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\n", 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) ? ‘\n‘ : ‘ ‘);
    }

    return 0;
}

  

时间: 2025-01-05 00:28:02

Codeforces Round #323 (Div. 2)的相关文章

2017-5-2-Train:Codeforces Round #323 (Div. 2)

A. Asphalting Roads(模拟) City X consists of n vertical and n horizontal infinite roads, forming n × n intersections. Roads (both vertical and horizontal) are numbered from 1 to n, and the intersections are indicated by the numbers of the roads that fo

Codeforces Round #323 (Div. 2) D.Once Again...

D. Once Again... You are given an array of positive integers a1, a2, ..., an × T of length n × T. We know that for any i > n it is true that ai = ai - n. Find the length of the longest non-decreasing sequence of the given array. Input The first line

Codeforces Round #323 (Div. 2) D. Once Again... 暴力+最长非递减子序列

                                                                              D. Once Again... You are given an array of positive integers a1, a2, ..., an × T of length n × T. We know that for any i > n it is true that ai = ai - n. Find the length of

Codeforces Round #323 (Div. 2) C. GCD Table

C. GCD Table The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both

Codeforces Round #323 (Div. 2) E - Superior Periodic Subarrays

E - Superior Periodic Subarrays 好难的一题啊... 这个博客讲的很好,搬运一下. https://blog.csdn.net/thy_asdf/article/details/49406133 #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define pii pair<int,int> #de

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿

Codeforces Round #424 (Div. 2) C. Jury Marks(乱搞)

题目链接:Codeforces Round #424 (Div. 2) C. Jury Marks 题意: 给你一个有n个数序列,现在让你确定一个x,使得x通过挨着加这个序列的每一个数能出现所有给出的k个数. 问合法的x有多少个.题目保证这k个数完全不同. 题解: 显然,要将这n个数求一下前缀和,并且排一下序,这样,能出现的数就可以表示为x+a,x+b,x+c了. 这里 x+a,x+b,x+c是递增的.这里我把这个序列叫做A序列 然后对于给出的k个数,我们也排一下序,这里我把它叫做B序列,如果我