Educational Codeforces Round 18 A B 码力 比赛

  比赛链接: https://vjudge.net/contest/180067#overview

      A: New Bus Route

  题目描述: 略

  解题思路: 排序

  代码: 

#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iterator>
#include <cmath>
#include <algorithm>
#include <stack>
#include <deque>
#include <map>
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
#define fi(n) for(i=0;i<n;i++)
#define fj(m) for(j=0;j<m;j++)
#define sca(x) scanf("%d",&x)
#define scalld(x) scanf("%I64d",&x)
#define print(x) printf("%d\n",x)
#define printlld(x) printf("%I64d\n",x)
#define d printf("=======\n")
typedef long long ll;
using namespace std;

const int INF = 1e11;
const int maxn = 2e5 + 100;
ll a[maxn];

int main() {
    int n;
    scanf( "%d", &n );
    for( int i = 0; i < n; i++ ) {
        scanf( "%lld", a+i );
    }
    sort(a, a+n);
    ll mind = INF;
    for( int i = 1; i < n; i++ ) {
        ll temp = abs(a[i] - a[i-1]);
        mind = min( mind, temp );
    }
    int cnt = 0;
    for( int i = 1; i < n; i++ ) {
        ll temp = abs(a[i]-a[i-1]);
        if( mind == temp ) {
            cnt++;
        }
    }
    printf( "%lld %d\n", mind, cnt );
    return 0;
}
View Code

  思考: 自己INF开小了, WA了, 心太大

      B: Counting-out Rhyme  

  题目描述: 约瑟夫环

  解题思路: 暴力

  代码: 

#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iterator>
#include <cmath>
#include <algorithm>
#include <stack>
#include <deque>
#include <map>
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
#define fi(n) for(i=0;i<n;i++)
#define fj(m) for(j=0;j<m;j++)
#define sca(x) scanf("%d",&x)
#define scalld(x) scanf("%I64d",&x)
#define print(x) printf("%d\n",x)
#define printlld(x) printf("%I64d\n",x)
#define d printf("=======\n")
typedef long long ll;
using namespace std;

const int INF = 1e11;
const int maxn = 500;
int a[maxn];
int b[maxn];

int main() {
    int n, k;
    cin >> n >> k;
    for( int i = 1; i <= k; i++ ) {
        cin >> a[i];
    }
    for( int i = 0; i < n; i++ ) {
        b[i] = i;
    }
    int cur = 0;
    int temp = n;
    for( int i = 1; i <= k; i++ ) {
        int mod = a[i] % temp;
//        cout << mod << endl;
//        cout << mod << endl;
        while( 1 ) {
            if( b[cur] == -1 ) cur = (cur + 1) % n;
            if( mod == 0 ) {
                while( b[cur] == -1 ) {
                    cur = (cur+1) % n;
                }
                break;
            }
            if( b[cur] >= 0 ) {
                cur = (cur + 1) % n;
                mod--;
            }
        }
//        cout << cur << endl;
        b[cur] = -1;
        if( i == 1 ) {
            cout << cur+1;
        }
        else {
            cout << " " << cur+1;
//            cout << " " << cur+1;
        }
        while( 1 ) {
            cur = (cur+1) % n;
            if( b[cur] >= 0 ) break;
        }
//        cout << cur << endl;
        temp--;
    }
    cout << endl;
    return 0;
}
View Code

  思考: 做的麻烦了, 我这么做很容易出错, 应该直接放进set里

  

 

  比赛总结: C做不出来 , 本来想拿DP做, 状态方程也转移出来了, 但是还是有的地方考虑不周到, 感觉自己现在做题有点儿不顺, 今晚儿打CF

 

https://vjudge.net/contest/180067#overview

 

posted on 2017-08-18 16:53  FriskyPuppy  阅读(172)  评论(0编辑  收藏  举报

导航