2015 重庆市赛 解题报告

原创 2015年11月19日 21:43:21

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;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

2015 CQU 重庆大学程序设计竞赛 解题报告

前言 儿童节快乐~~ 啊对了首先想带标程回家看的可以来这里:教主大大标程包 / 我的现场赛代码 在校赛这样三人组队两台电脑的环境下,单挑的压力着实是十分之大……毕竟在同等条件下别人手速只要超过自己的...
  • okcd00
  • okcd00
  • 2015年06月01日 13:35
  • 2209

Delphi7高级应用开发随书源码

  • 2003年04月30日 00:00
  • 676KB
  • 下载

NOIP2015提高组解题报告

  • 2015年11月24日 11:07
  • 70KB
  • 下载

2015 ICPC 长春网赛 解题报告

只A了几道水题,还好晋级了。 07 The Water Problem         果然是水题,随便模拟一下就好了。为了题解完整性贴出来。 #include #include ...

2015 亚洲区域赛长春赛区网络赛解题报告(9/13)

这场比赛由东北师范大学出题,题目共13道,冠军过了12道,出线需要6道,整体上难度不是很大。 1001 Alisha’s Party 题意:Alisha有n个朋友来参加她的party,每个朋友来的时候...

2015 暑假集训14级第一周周赛解题报告

A.小模拟题 根据要求模拟即可。没什么可讲的。。 参考代码:http://paste.ubuntu.com/11978075/B.组合计数 首先排序,然后可以在O(n)复杂度内求出每个hero所...

2012浙江省赛解题报告

  • 2013年09月16日 15:15
  • 9KB
  • 下载

浙大zoj月赛解题报告及代码

  • 2011年03月25日 16:16
  • 18KB
  • 下载

NOI2015补全+解题报告

NOI2015解题报告

JZOJ.4302[NOIP2015模拟11.3]IOIOI卡片占卜 解题报告

IOIOI卡片占卜题目大意给5个正整数AA,BB,CC,DD,EE。表示由AA个1,BB个0,CC个1,DD个0,EE个1连接组成的序列。 接下来给出nn个操作,每个操作两个整数ll,rr,表示把l...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:2015 重庆市赛 解题报告
举报原因:
原因补充:

(最多只允许输入30个字)