2015 重庆市赛 解题报告

A. 蠕虫爬井

题意:

0,n,1u,1d,

分析:

d>=u,,
,,,

代码:

//
//  Created by TaoSama on 2015-11-18
//  Copyright (c) 2015 TaoSama. All rights reserved.
//
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>

using namespace std;
#define pr(x) cout << #x << " = " << x << "  "
#define prln(x) cout << #x << " = " << x << endl
const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;

int n, u, d;

int main() {
#ifdef LOCAL
    freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);
//  freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(0);

    while(scanf("%d%d%d", &n, &u, &d) == 3) {
        if(u >= n) puts("1");
        else if(u <= d) puts("The worm can't escape from the well.");
        else {
            int ans = 1;
            n -= u; u -= d;
            ans += (n + u - 1) / u * 2;
            printf("%d\n", ans);
        }
    }
    return 0;
}

B. 回文数挑选

题意:

18

分析:

代码:

//
//  Created by TaoSama on 2015-11-19
//  Copyright (c) 2015 TaoSama. All rights reserved.
//
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>

using namespace std;
#define pr(x) cout << #x << " = " << x << "  "
#define prln(x) cout << #x << " = " << x << endl
const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;

char s[25];

int main() {
#ifdef LOCAL
    freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);
//  freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(0);

    while(scanf("%s", s) == 1) {
        int n = strlen(s);
        bool ok = true;
        for(int i = 0; i < n >> 1; ++i) {
            if(s[i] != s[n - i - 1]) {
                ok = false;
                break;
            }
        }
        printf("%s ", s);
        puts(ok ? "is a palindromic number." : "is not a palindromic number.");
    }
    return 0;
}

C. 有趣的数字图形

题意:

分析:

,

代码:

//
//  Created by TaoSama on 2015-11-19
//  Copyright (c) 2015 TaoSama. All rights reserved.
//
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>

using namespace std;
#define pr(x) cout << #x << " = " << x << "  "
#define prln(x) cout << #x << " = " << x << endl
const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;

int n, a[15][15];

int main() {
#ifdef LOCAL
    freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);
//  freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(0);

    int kase = 0;
    while(scanf("%d", &n) == 1) {
        memset(a, 0, sizeof a);
        int x, y, cnt = a[x = 1][y = 1] = 1;
        while(cnt < n * n) {
            while(y + 1 <= n && !a[x][y + 1]) a[x][++y] = ++cnt;
            while(x + 1 <= n && !a[x + 1][y]) a[++x][y] = ++cnt;
            while(y - 1 >= 1 && !a[x][y - 1]) a[x][--y] = ++cnt;
            while(x - 1 >= 1 && !a[x - 1][y]) a[--x][y] = ++cnt;
        }
        if(kase++) puts("");
        for(x = 1; x <= n; ++x) {
            for(y = 1; y <= n; ++y)
                printf("%3d", a[x][y]);
            puts("");
        }
    }
    return 0;
}

D. 奇怪的木匠

题意:

[0,10],5,,,

分析:

gcdgcd,,int

代码:

//
//  Created by TaoSama on 2015-11-19
//  Copyright (c) 2015 TaoSama. All rights reserved.
//
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>

using namespace std;
#define pr(x) cout << #x << " = " << x << "  "
#define prln(x) cout << #x << " = " << x << endl
const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;

typedef long long LL;

LL n, a, b, c, OFF = 1e5;
string l, w, h;

LL ten(int x) {
    LL ret = 1;
    for(int i = 1; i <= x; ++i) ret *= 10;
    return ret;
}

void handle(string &l, LL& a) {
    if(l.find('.') == string::npos) {
        a = atoi(l.c_str()) * OFF;
        return;
    }
    int p = l.find('.'); l.erase(p, 1);
    a = atoi(l.c_str()) * ten(5 - (l.size() - p));
}

int main() {
#ifdef LOCAL
    freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);
//  freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(0);

    int t; cin >> t;
    while(t--) {
        cin >> l >> w >> h;
        handle(l, a);
        handle(w, b);
        handle(h, c);
        LL each = __gcd(a, __gcd(b, c));
        LL ans = a * b * c / (each * each * each);
        cout << ans << '\n';
    }
    return 0;
}

E. 加倍或清0

题意:

,,线,,线

分析:

dp[i][j]:=i,j
O(n2),O(1),,
,
这里写图片描述
dp[i][j]a[i]<jdown[i][j]
dp[i][j]b[j]<iup[i][j]
,,O(1)

代码:

//
//  Created by TaoSama on 2015-11-19
//  Copyright (c) 2015 TaoSama. All rights reserved.
//
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>

using namespace std;
#define pr(x) cout << #x << " = " << x << "  "
#define prln(x) cout << #x << " = " << x << endl
const int N = 1e3 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;

int n, m, a[N], b[N];
int dp[N][N], down[N][N], up[N][N];

int main() {
#ifdef LOCAL
    freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);
//  freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(0);

    int t; scanf("%d", &t);
    while(t--) {
        scanf("%d%d", &n, &m);
        for(int i = 1; i <= n; ++i) scanf("%d", a + i);
        for(int i = 1; i <= m; ++i) scanf("%d", b + i);

        for(int i = 2; i <= n; ++i) {
            for(int j = 2; j <= m; ++j) {
                if(a[i] == b[j - 1]) down[i][j] = j - 1;
                else down[i][j] = down[i][j - 1];
            }
        }
        for(int i = 2; i <= n; ++i) {
            for(int j = 2; j <= m; ++j) {
                if(b[j] == a[i - 1]) up[i][j] = i - 1;
                else up[i][j] = up[i - 1][j];
            }
        }

        for(int i = 2; i <= n; ++i) {
            for(int j = 2; j <= m; ++j) {
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
                if(a[i] == b[j]) continue;
                int a = down[i][j], b = up[i][j];
                if(a && b) dp[i][j] = max(dp[i][j], dp[b - 1][a - 1] + 2);
            }
        }
        printf("%d\n", dp[n][m]);
    }
    return 0;
}

F. 三角形中的格点

题意:

退

分析:

pick:S=a+b÷21abs
a,22:2a=2S+2b
,b(),gcd(x,y)1

坑:

abs,gcd

代码:

//
//  Created by TaoSama on 2015-11-19
//  Copyright (c) 2015 TaoSama. All rights reserved.
//
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>

using namespace std;
#define pr(x) cout << #x << " = " << x << "  "
#define prln(x) cout << #x << " = " << x << endl
const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;

struct Point {
    int x, y;
    void read() {scanf("%d%d", &x, &y);}
    Point operator- (const Point& p) const {
        return (Point) {x - p.x, y - p.y};
    }
    int operator^(const Point& p) const {
        return x * p.y - y * p.x;
    }
} a[3];

int getArea2() {
    return (a[1] - a[0]) ^ (a[2] - a[0]);
}

int main() {
#ifdef LOCAL
    freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);
//  freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(0);

    while(true) {
        bool ok = false;
        for(int i = 0; i < 3; ++i) {
            a[i].read();
            if(a[i].x || a[i].y) ok = true;
        }
        if(!ok) break;

        //pick theorem S = in + side/2 - 1
        int s = abs(getArea2()), side = 3;
        for(int i = 0; i < 3; ++i) {
            Point t = a[i] - a[(i + 1) % 3];
            side += abs(__gcd(t.x, t.y)) - 1;
        }
        int ans = s + 2 - side >> 1;
        printf("%d\n", ans);
    }
    return 0;
}

G. Cross a Lake

题意:

N105,2,H,9901

分析:

dp,dp[i]:=a[i]
dp[i]=dp[j]++dp[k]+1,dp[j]a[i]h,dp[k]a[i]+h
1,O(n),,BITdp[i],O(logn)
,
12,n1

注意:

,,ans=((xy)%MOD+MOD)%MOD

代码:

//
//  Created by TaoSama on 2015-11-19
//  Copyright (c) 2015 TaoSama. All rights reserved.
//
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>

using namespace std;
#define pr(x) cout << #x << " = " << x << "  "
#define prln(x) cout << #x << " = " << x << endl
const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 9901;

int n, h, a[N], b[N];

void add(int i, int v) {
    for(; i <= n; i += i & -i) b[i] += v;
}

int sum(int i) {
    int ret = 0;
    for(; i; i -= i & -i) ret += b[i];
    return ret;
}

int main() {
#ifdef LOCAL
    freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);
//  freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(0);

    while(scanf("%d%d", &n, &h) == 2) {
        vector<int> xs;
        for(int i = 1; i <= n; ++i) {
            scanf("%d", a + i);
            xs.push_back(a[i]);
        }
        sort(xs.begin(), xs.end());
        xs.resize(unique(xs.begin(), xs.end()) - xs.begin());

        memset(b, 0, sizeof b);
        for(int i = 1; i <= n; ++i) {
            int o = lower_bound(xs.begin(), xs.end(), a[i]) - xs.begin() + 1;
            int l = lower_bound(xs.begin(), xs.end(), a[i] - h) - xs.begin() + 1;
            int r = upper_bound(xs.begin(), xs.end(), a[i] + h) - xs.begin();
            int tmp = (sum(r) - sum(l - 1)) % MOD;
            add(o, tmp + 1);
        }
        int ans = ((sum(n) - n) % MOD + MOD) % MOD;
        printf("%d\n", ans);
    }
    return 0;
}

H. A Pilot in Danger

题意:

(0,0)n16,px+qy(x,y0, 2p,q1000),safe

分析:

使
ans=(p1)(q1)/2 证明见: 戳我看证明
,pq,使exgcd
pq,,

代码:

//
//  Created by TaoSama on 2015-11-19
//  Copyright (c) 2015 TaoSama. All rights reserved.
//
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>

using namespace std;
#define pr(x) cout << #x << " = " << x << "  "
#define prln(x) cout << #x << " = " << x << endl
const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;
const double EPS = 1e-8;

int n;

int sgn(double x) {return x < -EPS ? -1 : x < EPS ? 0 : 1;}

struct Point {
    double x, y, ang;
    Point(double x = 0, double y = 0): x(x), y(y) {}
    void read() {scanf("%lf%lf", &x, &y); ang = atan2(y, x);}
    Point operator- (const Point& p) const {
        return (Point) {x - p.x, y - p.y};
    }
    double operator* (const Point& p) const {
        return x * p.x + y * p.y;
    }
    double operator^ (const Point& p) const {
        return x * p.y - y * p.x;
    }
    bool operator< (const Point& p) const {
        return ang < p.ang;
    }
} a[20];

bool onSeg(Point p, Point a, Point b) {
    return sgn((a - p ^ b - p) == 0 && sgn((a - p) * (b - p)) <= 0);
}

int isPointInPolygon(Point p) {
    int wn = 0;
    for(int i = 0; i < n; ++i) {
        if(onSeg(p, a[i], a[i + 1])) return -1;
        int k = sgn(a[i + 1] - a[i] ^ p - a[i]);
        int d1 = sgn(a[i].y - p.y);
        int d2 = sgn(a[i + 1].y - p.y);
        if(k > 0 && d1 <= 0 && d2 > 0) ++wn;
        if(k < 0 && d2 <= 0 && d1 > 0) --wn;
    }
    if(wn != 0) return 1;
    return 0;
}

int main() {
#ifdef LOCAL
    freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);
//  freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(0);

    int kase = 0;
    while(scanf("%d", &n) == 1 && n) {
        for(int i = 0; i < n; ++i) a[i].read();
        int p, q; scanf("%d%d", &p, &q);
        a[n] = a[0];

        printf("Pilot %d\n", ++kase);
        if(isPointInPolygon(Point(0, 0)) == 0) {
            puts("The pilot is safe.\n");
            continue;
        }
        puts("The pilot is in danger!");
        printf("The secret number is %d.\n\n", (p - 1) * (q - 1) >> 1);
    }
    return 0;
}
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值