南华大学ACM新生赛暑假第一场题目和标程

                        南华大学ACM新生赛暑假第一场题目和标程
武汉大学第六届Eming杯程序设计竞赛初赛

A.Eming

Eming is a contest hold by WHUACM training team. The aim is to select new members of the team. 

Usually, the first problem is a very simple problem such as “a+b problem”. But this time, Xioumu is tired of this kind of problem, he decide to solve “a and b problem”.

Give you the result of a + b and a^2 – b^2, please output the result of a and b.

Input

There are several test cases. For each case there are two double numbers indicating a+b and a^2-b^2. You may assume that a+b will not be zero.

Output

For each case please output the result of a and b in one line, rounded to 2 decimal places.

Sample Input

3 -3

Sample Output

1.00 2.00


B.ArithmetiProgression

“In mathematics, an arithmetic progression (AP) or arithmetic sequence is a sequence of numbers such that the difference between the consecutive terms is constant. For instance, the sequence 5, 7, 9, 11, 13, … is an arithmetic progression with common difference of 2.”

Wikipedia

This is a quite simple problem, give you the sequence, you are supposed to find the length of the longest consecutive subsequence which is an arithmetic progression.

Input

There are several test cases. For each case there are two lines. The first line contains an integer number N (1 <= N <= 100000) indicating the number of the sequence. The following line describes the N integer numbers indicating the sequence, each number will fit in a 32bit signed integer.

Output

For each case, please output the answer in one line.

Sample Input

6

1 4 7 9 11 14

Sample Output

3

C.An Easy Puz

Wddpdh find an interesting mini-game in the BBS of WHU, called “An easy PUZ”. It’s a 6 * 6 chess board and each cell has a number in the range of 0 and 3(it can be 0, 1, 2 or 3). Each time you can choose a number A(i, j) in i-th row and j-th column, then the number A(i, j) and the numbers around it (A(i-1, j), A(i+1, j),A(i, j-1),A(i, j+1), sometimes there may just be 2 or 3 numbers.) will minus 1 (3 to 2, 2 to 1, 1 to 0, 0 to 3). You can do it finite times. The goal is to make all numbers become 0. Wddpdh now come up with an extended problem about it. He will give you a number N (3 <= N <= 6) indicate the size of the board. You should tell him the minimum steps to reach the goal.

Input

The input consists of multiple test cases. For each test case, it contains a positive integer N(3 <= n <= 6). N lines follow, each line contains N columns indicating the each number in the chess board.

Output

For each test case, output minimum steps to reach the goal. If you can’t reach the goal, output -1 instead.

Sample Input

3

1 1 0

1 0 1

0 1 1

3

2 3 1

2 2 1

0 1 0

Sample Output

2

3

D.Brackets 

This year MK is 5 years old. So he decides to learn some arithmetic. But he was confused by how to write the brackets. He has already known that the brackets should match when writing them correctly. Such as “()(())” is correct but “())(” is not.

The problem is that, if there are N pairs of brackets, how many ways that MK can write them correctly?           

Input 

   There are several test cases. Each case contains a number N (1 <= N <= 1000) indicating the pairs of brackets.

Output 

For each case, please output the answer mod 1,000,000,007.

Sample Input 

5

7

Sample Output 

42

429

E.Function

Define a function f(n)=(f(n-1)+1)/f(n-2). You already got f(1) and f(2). Now, give you a number m, please find the value of f(m).

Input

There are several test cases. Each case contains three integers indicating f(1), f(2) and m ( 1 <= f(1), f(2), m <= 1000,000,000).

Output

For each case, please output the value of f(m), rounded to 6 decimal places.

Sample Input

1 1 3

Sample Output

2000000

F.Triangle

It is a simple task, for N points on the 2D plane, you are supposed to find whether there are three points which could form a isosceles triangle.

Input

There are several test cases. For each case, the first line is an integer N (3 <= N <= 500) indicating the number of points. N lines follow, each line contains two doubles(not exceed 1000.0), indicating the coordinates of the points.

Output

For each case, if there exists a solution which could form a isosceles triangle, output “YES”, else output “NO”.

Sample Input

3

0 0

1 1

-1 1

3

0 0

1 1

5 10

Sample Output

YES
NO


一下是oj上的源码:

A:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;
#define out(v) cerr << #v << ": " << (v) << endl
#define SZ(v) ((int)(v).size())
const int maxint = -1u>>1;
template <class T> bool get_max(T& a, const T &b) {return b > a? a = b, 1: 0;}
template <class T> bool get_min(T& a, const T &b) {return b < a? a = b, 1: 0;}

int main() {
    //freopen("Eming.out", "w", stdout);
    double A, B, C;
    while(scanf("%lf%lf", &A, &B) == 2) {
        C = B / A;
        printf("%.2lf %.2lf\n", (A + C) * 0.5, (A - C) * 0.5);
    }
    return 0;
}


B:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;
#define out(v) cerr << #v << ": " << (v) << endl
#define SZ(v) ((int)(v).size())
const int maxint = -1u>>1;
template <class T> bool get_max(T& a, const T &b) {return b > a? a = b, 1: 0;}
template <class T> bool get_min(T& a, const T &b) {return b < a? a = b, 1: 0;}

const int maxn = 100000 + 5;
int seq[maxn], n;

int main() {
    //freopen("ap.out", "w", stdout);
    while(scanf("%d", &n) == 1) {
        for(int i = 0; i < n; i++) {
            scanf("%d", seq + i);
        }
        int ans = 1, s = 0, t, d;
        while(s < n - 1) {
            t = s + 1, d = seq[t] - seq[s];
            while(t < n && seq[t] - seq[t - 1] == d) t++;
            t--;
            get_max(ans, t - s + 1);
            s = t;
        }
        printf("%d\n", ans);
    }
    return 0;
}


C:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;
#define out(v) cerr << #v << ": " << (v) << endl
#define SZ(v) ((int)(v).size())
const int maxint = -1u>>1;
template <class T> bool get_max(T& a, const T &b) {return b > a? a = b, 1: 0;}
template <class T> bool get_min(T& a, const T &b) {return b < a? a = b, 1: 0;}

const int maxn = 10;

int n, mat[maxn][maxn], rm[maxn][maxn], tr[maxn][maxn], ans;

int dx[] = {0, -1, 1, 0, 0};
int dy[] = {0, 0, 0, -1, 1};

bool inboard(int x, int y) {
    return 0 <= x && x < n && 0 <= y && y < n;
}

void fix(int &u, int v) {
    u += v;
    u = (u % 4 + 4) % 4;
}

void update() {
    memcpy(rm, mat, sizeof(rm));
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            for(int dir = 0; dir < 5; dir++) {
                int x = i + dx[dir];
                int y = j + dy[dir];
                if(!inboard(x, y)) continue;
                fix(rm[x][y], -tr[i][j]);
            }
        }
        if(i + 1 < n) {
            for(int j = 0; j < n; j++) {
                tr[i + 1][j] = rm[i][j];
            }
        }
    }
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            if(rm[i][j]) return;
        }
    }
    int sum = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            sum += tr[i][j];
        }
    }
    if(ans == -1 || ans > sum) ans = sum;
}
                    
void dfs(int step) {
    if(step == n) {
        update();
        return;
    }
    for(int i = 0; i < 4; i++) {
        tr[0][step] = i;
        dfs(step + 1);
    }
}

int main() {
    //freopen("Puz.out", "w", stdout);
    while(scanf("%d", &n) == 1) {
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                scanf("%d", &mat[i][j]);
            }
        }
        ans = -1;
        dfs(0);
        printf("%d\n", ans);
    }
    return 0;
}


D:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;
#define out(v) cerr << #v << ": " << (v) << endl
#define SZ(v) ((int)(v).size())
const int maxint = -1u>>1;
template <class T> bool get_max(T& a, const T &b) {return b > a? a = b, 1: 0;}
template <class T> bool get_min(T& a, const T &b) {return b < a? a = b, 1: 0;}

const int maxn = 1000 + 5;
const int MOD = 1000000007;

typedef long long lint;

int n;
lint f[maxn];

int main() {
    //freopen("bracket.out", "w", stdout);
    f[0] = 1;
    for(int i = 1; i <= 1000; i++) {
        for(int j = 0; j < i; j++) {
            f[i] += f[j] * f[i - j - 1] % MOD;
            f[i] %= MOD;
        }
    }
    while(scanf("%d", &n) == 1) {
        printf("%I64d\n", f[n]);
    }
    return 0;
}


E:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;
#define out(v) cerr << #v << ": " << (v) << endl
#define SZ(v) ((int)(v).size())
const int maxint = -1u>>1;
template <class T> bool get_max(T& a, const T &b) {return b > a? a = b, 1: 0;}
template <class T> bool get_min(T& a, const T &b) {return b < a? a = b, 1: 0;}

int m;
double a, b;
vector<double> v;

int main() {
    //freopen("fun.in", "r", stdin);
    //freopen("fun.out", "w", stdout);
    while(scanf("%lf%lf%d", &a, &b, &m) == 3) {
        v.clear();
        v.push_back(a);
        v.push_back(b);
        while(v.size() < 5) {
            int sz = v.size();
            v.push_back((v[sz - 1] + 1.0) / v[sz - 2]);
        }
        m--;
        printf("%.6lf\n", v[m % 5]);
    }
    return 0;
}


F:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;

#define SZ(v) ((int)(v).size())
const int maxint = -1u>>1;
template <class T> bool get_max(T& a, const T &b) {return b > a? a = b, 1: 0;}
template <class T> bool get_min(T& a, const T &b) {return b < a? a = b, 1: 0;}

const double eps = 1e-9;

int sgn(double x) {
    return (x > eps) - (x < -eps);
}

struct point {
    double x, y;
    point(double _x = 0.0, double _y = 0.0) : x(_x), y(_y) {}
    double len() const {
        return sqrt(x * x + y * y);
    }
};

double operator * (const point &p1, const point &p2) {
    return p1.x * p2.y - p1.y * p2.x;
}

point operator - (const point &p1, const point &p2) {
    return point(p1.x - p2.x, p1.y - p2.y);
}

int n;
vector<point> v;

void out(const point &p) {
    printf("(%.2lf, %.2lf)\n", p.x, p.y);
} 

bool check() {
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            for(int k = 0; k < n; k++) {
                if(i == j || j == k || i == k) continue;
                point v1 = v[j] - v[i];
                point v2 = v[k] - v[i];
                if(sgn(v1.len() - v2.len()) == 0) {
                    if(sgn(v1 * v2)) {
                        out(v[i]); out(v[j]); out(v[k]);
                        printf("=============================\n");
                        return true;
                    }
                }
            }
        }
    }
    return false;
}

int main() {
    freopen("tri.in", "r", stdin);
    while(scanf("%d", &n) == 1) {
        v.clear();
        for(int i = 0; i < n; i++) {
            double x, y;
            scanf("%lf%lf", &x, &y);
            v.push_back(point(x, y));
        }
        if(check()) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <ctime>
using namespace std;
#define out(v) cerr << #v << ": " << (v) << endl
#define SZ(v) ((int)(v).size())
const int maxint = -1u>>1;
template <class T> bool get_max(T& a, const T &b) {return b > a? a = b, 1: 0;}
template <class T> bool get_min(T& a, const T &b) {return b < a? a = b, 1: 0;}

int n = 500;

int main() {
    freopen("tri.in",  "w", stdout);
    srand(time(0));
    for(int testCase = 0; testCase < 10; testCase++) {
        printf("%d\n", n);
        for(int i = 0; i < n; i++) {
            double x = rand() % 100000 / 10.0;
            double y = rand() % 100000 / 10.0;
            printf("%.1lf %.1lf\n", x, y);
        }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;
#define out(v) cerr << #v << ": " << (v) << endl
#define SZ(v) ((int)(v).size())
const int maxint = -1u>>1;
template <class T> bool get_max(T& a, const T &b) {return b > a? a = b, 1: 0;}
template <class T> bool get_min(T& a, const T &b) {return b < a? a = b, 1: 0;}

const double pi = acos(-1.0);
const double eps = 1e-9;

int sgn(double x) {
    return (x > eps) - (x < -eps);
}

int n;


struct point {
    double x, y;
    point() {}
    point(double _x, double _y) : x(_x), y(_y) {}
};

double dis(double x, double y) {
    return sqrt(x * x + y * y);
}

vector<point> pts;
vector< pair<double, double> > vec;

bool check(const vector< pair<double, double> > &vec) {
    for(int i = 0; i < vec.size(); i++) {
        double len = vec[i].first;
        double arc = vec[i].second;
        for(int j = i + 1; j < vec.size(); j++) {
            if(sgn(vec[j].first - len)) {
                i = j - 1;
                break;
            }
            else {
                if(sgn(arc - vec[j].second) == 0 || sgn(fabs(arc - vec[j].second) - pi) == 0) {
                }
                else {
                    return true;
                }
            }
        }
    }
    return false;
}

bool getAnswer() {
    for(int i = 0; i < n; i++) {
        vec.clear();
        for(int j = 0; j < n; j++) {
            if(i == j) continue;
            double arc = atan2(pts[j].y - pts[i].y, pts[j].x - pts[i].x);
            double len = dis(pts[j].y - pts[i].y, pts[j].x - pts[i].x);
            if(sgn(arc) < 0) arc += 2 * pi;
            
            vec.push_back(make_pair(len, arc));
        }
        sort(vec.begin(), vec.end());
        if(check(vec)) return true;
    }
    return false;
}
            
int main() {
    freopen("tri.out", "w", stdout);
    while(scanf("%d", &n) == 1) {
        pts.clear();
        for(int i = 0; i < n; i++) {
            double x, y;
            scanf("%lf%lf", &x, &y);
            pts.push_back(point(x, y));
        }
        printf(getAnswer() ? "YES\n": "NO\n");
    }
    return 0;
}






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值