Codeforces Good Bye 2016(部分题解)

Posted AC_Arthur

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Good Bye 2016(部分题解)相关的知识,希望对你有一定的参考价值。

本次比赛一共AC了前4题...

A. New Year and Hurry
水题。

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <ctime>
#include <bitset>
#include <cstdlib>
#include <cmath>
#include <set>
#include <list>
#include <deque>
#include <map>
#include <queue>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std;
typedef long long ll;
typedef long double ld;
const double eps = 1e-6;
const double PI = acos(-1);
const int mod = 1000000000 + 7;
const int INF = 0x3f3f3f3f;
// & 0x7FFFFFFF
const int seed = 131;
const ll INF64 = ll(1e18);
const int maxn = 1e5 + 10;
int k, n;


int main() 
    scanf("%d%d", &n, &k);
    int sum = 0, ans = 0;
    for(int i = 1; i <= n; i++) 
        sum += 5*i;
        if(sum + k <= 4*60) ++ans;
    
    printf("%d\\n", ans);

    return 0;



B. New Year and North Pole
其实向东西跑我们不用理睬(在南北极除外), 这样只需要记录当前距离北极多远就行了。

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <ctime>
#include <bitset>
#include <cstdlib>
#include <cmath>
#include <set>
#include <list>
#include <deque>
#include <map>
#include <queue>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std;
typedef long long ll;
typedef long double ld;
const double eps = 1e-6;
const double PI = acos(-1);
const int mod = 1000000000 + 7;
const int INF = 0x3f3f3f3f;
// & 0x7FFFFFFF
const int seed = 131;
const ll INF64 = ll(1e18);
const int maxn = 1e5 + 10;
int k, n;

char s[1000];
int main() 
    scanf("%d", &n);
    int dist = 0;
    bool ok = true;
    for(int i = 1; i <= n; i++) 
        int v; scanf("%d%s", &v, s);
        if(s[0] == 'E' || s[0] == 'W') 
            if(dist == 0 || dist == 20000) ok = false;
        
        else if(s[0] == 'N') 
            if(dist - v < 0)  ok = false; 
            else dist -= v;
        
        else 
            if(dist + v > 20000)  ok = false; 
            else dist += v;
        
    
    if(ok && dist == 0) printf("YES\\n");
    else printf("NO\\n");

    return 0;





C. New Year and Rating
我们假设初始可能值为x, 那么对于前i次的累加值cur, 第i+1次如果是div1, 那么x+cur >= 1900, 否则, x+cur < 1900, 这是一个不等式,  求出最终范围就行了。

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <ctime>
#include <bitset>
#include <cstdlib>
#include <cmath>
#include <set>
#include <list>
#include <deque>
#include <map>
#include <queue>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std;
typedef long long ll;
typedef long double ld;
const double eps = 1e-6;
const double PI = acos(-1);
const int mod = 1000000000 + 7;
const int INF = 0x3f3f3f3f;
// & 0x7FFFFFFF
const int seed = 131;
const ll INF64 = ll(1e18);
const int maxn = 2e5 + 10;
int k, n, a[maxn], b[maxn];

bool ok(int mid) 
    int ans = mid;

    for(int i = 1; i <= n; i++) 
        if(b[i] == 2) 
            if(ans >= 1900) return false;
        
        ans += a[i];
    
    return true;


bool hehe(int mid) 
    int cur = mid;
    for(int i = 1; i <= n; i++) 
        if(b[i] == 1) 
            if(cur < 1900) return false;
        
        else 
            if(cur >= 1900) return false;
        
        cur += a[i];
    
    return true;

char s[1000];
int main() 
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) 
        scanf("%d%d", &a[i], &b[i]);
    
    int res = 0, maxv = INF, minv = -INF;
    for(int i = 1; i <= n; i++) 
        if(b[i] == 1) 
            minv = max(minv, 1900-res);
        
        else 
            maxv = min(maxv, 1899-res);
        
        res += a[i];
//        printf("%d %d-\\n", minv, maxv);
    
    if(minv > maxv) printf("Impossible\\n");
    else if(maxv == INF) printf("Infinity\\n");
    else 
        for(int i = 1; i <= n; i++) 
            maxv += a[i];
        
        printf("%d\\n", maxv);
    
    return 0;





D. New Year and Fireworks
我们用dp[ceng][t][x][y][dir]表示状态:在(x, y)位置方向为dir,处于第ceng层烟花的第t个时间。   如果这个状态访问过剪枝即可。

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <ctime>
#include <bitset>
#include <cstdlib>
#include <cmath>
#include <set>
#include <list>
#include <deque>
#include <map>
#include <queue>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std;
typedef long long ll;
typedef long double ld;
const double eps = 1e-6;
const double PI = acos(-1);
const int mod = 1000000000 + 7;
const int INF = 0x3f3f3f3f;
// & 0x7FFFFFFF
const int seed = 131;
const ll INF64 = ll(1e18);
const int maxn = 150*2 + 10;
int n,  res = 0, t[maxn], vis[maxn][maxn];
bool d[30][6][maxn][maxn][9];

void dp(int ceng, int tt, int x, int y, int dir) 
    bool& ans = d[ceng][tt][x][y][dir];
    if(ceng >= n) return ;
    if(ans) return ;
    ans = 1;
    if(!vis[x][y]) res++, vis[x][y] = 1;

    if(dir == 0) 
        if(tt == t[ceng]) dp(ceng+1, 1, x-1, y+1, 1), dp(ceng+1, 1, x+1, y+1, 7);
        else dp(ceng, tt+1, x, y+1, dir);
    
    else if(dir == 1) 
        if(tt == t[ceng]) dp(ceng+1, 1, x, y+1, 0), dp(ceng+1, 1, x-1, y, 2);
        else dp(ceng, tt+1, x-1, y+1, dir);
    
    else if(dir == 2) 
        if(tt == t[ceng]) dp(ceng+1, 1, x-1, y+1, 1), dp(ceng+1, 1, x-1, y-1, 3);
        else dp(ceng, tt+1, x-1, y, dir);
    
    else if(dir == 3) 
        if(tt == t[ceng]) dp(ceng+1, 1, x-1, y, 2), dp(ceng+1, 1, x, y-1, 4);
        else dp(ceng, tt+1, x-1, y-1, dir);
    
    else if(dir == 4) 
        if(tt == t[ceng]) dp(ceng+1, 1, x-1, y-1, 3), dp(ceng+1, 1, x+1, y-1, 5);
        else dp(ceng, tt+1, x, y-1, dir);
    
    else if(dir == 5) 
        if(tt == t[ceng]) dp(ceng+1, 1, x, y-1, 4), dp(ceng+1, 1, x+1, y, 6);
        else dp(ceng, tt+1, x+1, y-1, dir);
    
    else if(dir == 6) 
        if(tt == t[ceng]) dp(ceng+1, 1, x+1, y-1, 5), dp(ceng+1, 1, x+1, y+1, 7);
        else dp(ceng, tt+1, x+1, y, dir);
    
    else if(dir == 7) 
        if(tt == t[ceng]) dp(ceng+1, 1, x, y+1, 0), dp(ceng+1, 1, x+1, y, 6);
        else dp(ceng, tt+1, x+1, y+1, dir);
    



int main() 
    scanf("%d", &n);
    for(int i = 0; i < n; i++) 
        scanf("%d", &t[i]);
    
    dp(0, 1, 160, 160, 0);



    printf("%d\\n", res);
    return 0;



就会这几道水题, 我也差不多是个废人了。


以上是关于Codeforces Good Bye 2016(部分题解)的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Good Bye 2016 D 模拟搜索?

Codeforces Good Bye 2016 E. New Year and Old Subsequence

Good Bye 2015 A

Codeforces 1091 (Good Bye 2018)

Codeforces Good Bye 2018 F

Codeforces Good Bye 2017 C. New Year and Curling 几何枚举