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重庆市赛总结

赛前: 上周跟着学长学姐们去打了重庆市赛。26个学校161个队规模还是蛮较大的,一开始我的内心的虚的qwq 和两个大二的学长组队,但是这两个学长都是很久没有打比赛的了。。。所以比赛之前我还是加紧练习了...
  • zyd8888102
  • zyd8888102
  • 2015年11月19日 20:15
  • 617

2015ACM浙江省省赛部分题解

The 12th Zhejiang Provincial Collegiate Programming Contest总体感觉题目有大概7道不涉及算法的题目。听群里讨论,现场赛有队伍一小时ac了7道题...
  • u013077144
  • u013077144
  • 2016年04月21日 19:00
  • 1444

2016ACM省赛总结

总结本该立马写的,然而题目刚要过来,再补充一下细节吧。    说下进度,第一个题目,A题,一道水题,我们登陆进去PC2后,就发现山理已经开了一血了,然后我们就是读题,这个进度不是很快,英语压制,向上...
  • huatian5
  • huatian5
  • 2016年06月07日 15:20
  • 1902

NOIp2015提高组 解题报告

比赛几个星期前就结束了,玩乐了一会儿,开始学术。 此文非题解。只是我自己的现场解题实录。 Day_0 到宾馆后紧张的要死。晚上写了一堆基础模板:spfa最短路径,prim和kruskal的最...
  • jr_mz
  • jr_mz
  • 2015年12月03日 18:34
  • 3871

2017年广东ACM省赛 I题 解题报告

这题明显是求最小生成树,但是点数n高达10^5,用传统的Krustal或Prim算法都会超时。这时需要更加高效的算法,用一种称为“三角剖分”的方法来优化。 其实我也不懂什么是“三角剖分”,但是查到有原...
  • li_wei_quan
  • li_wei_quan
  • 2017年05月08日 22:23
  • 887

NOIP 2015模拟赛 题解&总结

这场比赛总的来讲不是很难,区分度并不高,第一题属于思维训练类型,第二题是一个比较新的DP题,第三题转化一下就是贪心+背包了 总的来说,要根据题目中的已知条件来判断出题人的意图,比如第一题给出的范围 ...
  • getsum
  • getsum
  • 2016年11月11日 21:13
  • 583

西南科技大学 信息工程学院 院赛 部分题题解,持续更新.

【萌萌院赛之A】 【题目链接】点击打开链接 【题意】由于中文题目,就不说题意! 【解题思路】简单求根公式的应用! 【AC代码】 #include typedef long long LL; cons...
  • just_sort
  • just_sort
  • 2016年06月05日 21:03
  • 865

NOI 2015 滞后赛解题报告

报同步赛的时候出了些意外,于是只能做一做“滞后赛”了2333 DAY1 T1离线+离散化搞,对于相等的部分直接并查集,不等部分查看是否在同一并查集中即可,code:#include #includ...
  • Lcomyn
  • Lcomyn
  • 2015年08月14日 15:38
  • 1150

2015-2016 ACM-ICPC Pacific Northwest Regional Contest Div.2 全部题目题解

做一套题真是太令人疲惫了!
  • Kiritow
  • Kiritow
  • 2016年08月15日 21:29
  • 999

hihoCoder1252 2015北京区域赛 D.Kejin Game

题意:给你一个有向无环图的技能树,通常地学习某个技能需要学习全部的前置技能,并且需要一定的花费,但你可以通过氪金来消掉某个前置关系或者直接强行习得某个技能,问要学习某个特定的技能需要的最小花费; 一...
  • tianji_fange_tuhao
  • tianji_fange_tuhao
  • 2016年06月02日 12:06
  • 582
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:2015 重庆市赛 解题报告
举报原因:
原因补充:

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