广东工业大学2017新生赛(决赛)-网络同步赛

1002

模拟即可

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define lson (rt << 1)
#define rson ((rt << 1) | 1)
#define pill pair
#define mst(a, b)    memset(a, b, sizeof a)
#define REP(i, x, n)    for(int i = x; i <= n; ++i)
const int MOD = 1e9 + 7;
const int qq = 1e5 + 10;
const int INF = 1e9 + 10;
const double PI = 3.14159;

int main(){
    int t;    scanf("%d", &t);
    while (t--) {
        int n;    scanf("%d", &n);
        double maxn = 0;
        char st[10];
        double x, y;
        for(int i = 0; i < n; ++i) {
            scanf("%s", st);
            if(st[0] == 'T') {
                scanf("%lf%lf", &x, &y);
                maxn = max(maxn, x * y / 2);
            } else if (st[0] == 'R') {
                scanf("%lf%lf", &x, &y);
                maxn = max(maxn, x * y);
            } else if(st[0] == 'C') {
                scanf("%lf", &x);
                maxn = max(maxn, x * x * PI);
            }
        }
        printf("%.2lf\n", maxn);
    }
    return 0;
}


1003

做一个前缀和,然后枚举区间[i, j]

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define lson (rt << 1)
#define rson ((rt << 1) | 1)
#define pill pair
#define mst(a, b)    memset(a, b, sizeof a)
#define REP(i, x, n)    for(int i = x; i <= n; ++i)
const int MOD = 1e9 + 7;
const int qq = 1e5 + 10;
const int INF = 1e9 + 10;
LL sum[qq];

int main(){
    int t;    scanf("%d", &t);
    while (t--) {
        LL n, k;    scanf("%lld%lld", &n, &k);
        sum[0] = 0;
        for(int i = 1; i <= n; ++i) {
            scanf("%lld", sum + i);
            sum[i] += sum[i - 1];
        }
        bool f = false;
        for(int i = 1; i <= n; ++i) {
            for(int j = 1; j <= n; ++j) {
                if(sum[j] - sum[i - 1] == k) {
                    printf("%d %d\n", i, j);
                    f = true;
                }
                if(f)    break;
            }
            if(f)    break;
        }
    }
    return 0;
}


1004

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define lson (rt << 1)
#define rson ((rt << 1) | 1)
#define pill pair
#define mst(a, b)    memset(a, b, sizeof a)
#define REP(i, x, n)    for(int i = x; i <= n; ++i)
const int MOD = 1e9 + 7;
const int qq = 1e5 + 10;
const int INF = 1e9 + 10;
int p[10];
bool check(int dig[]) {
    for(int i = 0; i < 10; ++i) {
        if(dig[i] > 0)    return true;
    }
    return false;
}

int main(){
    p[0] = 1;
    for(int i = 1; i <= 8; ++i) {
        p[i] = p[i - 1] * 10;
    }
    int t;    scanf("%d", &t);
    while (t--) {
        int dig[10] = {0};
        int cnt = 0;
        int x;    scanf("%d", &x);
        while (x > 0) {
            dig[cnt++] = x % 10;
            x /= 10;
        }
        vector ans;
        while(check(dig)) {
            int tm = 0;
            for(int i = 0; i < cnt; ++i) {
                if(dig[i]) {
                    tm += p[i];
                    dig[i] --;
                }
            }
            ans.pb(tm);
        }
        sort(ans.begin(), ans.end());
        printf("%d\n", (int)ans.size());
        for(int i = 0; i < ans.size(); ++i) {
            if(i)    putchar(' ');
            printf("%d", ans[i]);
        }
        puts("");
    }
    return 0;
}


1005

广东工业大学2017新生赛(决赛)-网络同步赛_第1张图片


如果图形是这样的,我们很容易就可以肯定矩阵ABCD 和 正方形AFDE面积相等

三角形AFD刚好是矩形ABCD面积的一半同时也是正方形AFDE面积的一半

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define lson (rt << 1)
#define rson ((rt << 1) | 1)
#define pill pair
#define mst(a, b)    memset(a, b, sizeof a)
#define REP(i, x, n)    for(int i = x; i <= n; ++i)
const int MOD = 10007;
const int qq = 1e5 + 10;
const int INF = 1e9 + 10;

int main(){
    int t;    scanf("%d", &t) ;
    while (t--) {
        LL n, m;    scanf("%lld%lld", &n, &m);
        printf("%lld\n", n * m % MOD);
    }
    return 0;
}


1006

求和的形式可以写成这样子 sum = 5 * (1 + 2 + ... + n) = 5 + 10 + 15 + ... + 5 * n

所以我们求一下区间内有多少个5和7的倍数求一下和,然后利用容斥原理减去多算的部分和即可

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define lson (rt << 1)
#define rson ((rt << 1) | 1)
#define pill pair
#define mst(a, b)    memset(a, b, sizeof a)
#define REP(i, x, n)    for(int i = x; i <= n; ++i)
const int MOD = 1e9 + 7;
const int qq = 1e5 + 10;
const int INF = 1e9 + 10;
LL Solve (LL n, int x) {
    LL num = n / x;
    if(num <= 0)    return 0;
    return 1LL * x * (1LL + num) * num / 2;
}

int main(){
    int t;    scanf("%d", &t);
    while (t--) {
        LL n;    scanf("%lld", &n);
        printf("%lld\n", Solve(n, 5) + Solve(n, 7) - Solve(n, 35));
    }
    return 0;
}


1007

错排公式

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define lson (rt << 1)
#define rson ((rt << 1) | 1)
#define pill pair
#define mst(a, b)    memset(a, b, sizeof a)
#define REP(i, x, n)    for(int i = x; i <= n; ++i)
const int MOD = 1e9 + 7;
const int qq = 1e5 + 10;
const int INF = 1e9 + 10;
LL dp[20];

int main(){
    dp[1] = 0;
    dp[2] = 1;
    for(int i = 3; i <= 18; ++i) {
        dp[i] = 1LL * (i - 1) * (dp[i - 1] + dp[i - 2]);
    }
    int t;    scanf("%d", &t);
    while (t--) {
        int n;    scanf("%d", &n);
        printf("%lld\n", dp[n]);
    }
    return 0;
}

1008

答案范围在[1, 1000] 不妨从小到大枚举一下答案,再判断是否够k个即可

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define lson (rt << 1)
#define rson ((rt << 1) | 1)
#define pill pair
#define mst(a, b)    memset(a, b, sizeof a)
#define REP(i, x, n)    for(int i = x; i <= n; ++i)
const int MOD = 1e9 + 7;
const int qq = 1e5 + 10;
const int INF = 1e9 + 10;
int num[qq];

int main(){
    int t;    scanf("%d", &t);
    while (t--) {
        int n, k;    scanf("%d%d", &n, &k);
        for(int i = 1; i <= n; ++i) {
            scanf("%d", num + i);
        }
        int ans;
        for(int i = 1; i <= 1000; ++i) {
            int cnt = 0;
            for(int j = 1; j <= n; ++j) {
                if(i % num[j] == 0)    cnt++;
            }
            if(cnt >= k) {
                ans = i;
                break;
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}


1009

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define lson (rt << 1)
#define rson ((rt << 1) | 1)
#define pill pair
#define mst(a, b)    memset(a, b, sizeof a)
#define REP(i, x, n)    for(int i = x; i <= n; ++i)
const int MOD = 1e9 + 7;
const int qq = 1e5 + 10;
const int INF = 1e9 + 10;
char st[3] = {'R', 'u', 'a'};

int main(){
    int t;    scanf("%d", &t);
    while (t--) {
        int n;    scanf("%d", &n);
        for(int i = 0; i < n; ++i) {
            printf("%s\n", st);
        }
        puts("");
    }
    return 0;
}


1010

二进制枚举一下+ - 号即可

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define lson (rt << 1)
#define rson ((rt << 1) | 1)
#define pill pair
#define mst(a, b)    memset(a, b, sizeof a)
#define REP(i, x, n)    for(int i = x; i <= n; ++i)
const int MOD = 1e9 + 7;
const int qq = 1e5 + 10;
const int INF = 1e9 + 10;
int num[10];

int main(){
    int t;    scanf("%d", &t) ;
    while (t--) {
        for(int i = 0; i < 5; ++i) {
            scanf("%d", num + i);
        }
        int cnt = 0;
        for(int i = 0; i < (1 << 4); ++i) {
            int sum = 0;
            for(int j = 0; j < 4; ++j) {
                if(i & (1 << j))    sum += num[j + 1];
                else    sum -= num[j + 1];
            }
            sum += num[0];
            if(sum == 24)    cnt++;
        }
        printf("%d\n", cnt);
    }
    return 0;
}


1011

原式可以化成 y = (a * x - c) / b,x和y都是正整数,由此可以转化为判断是否存在(a * x - c) % b = 0

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define lson (rt << 1)
#define rson ((rt << 1) | 1)
#define pill pair
#define mst(a, b)    memset(a, b, sizeof a)
#define REP(i, x, n)    for(int i = x; i <= n; ++i)
const int MOD = 1e9 + 7;
const int qq = 1e5 + 10;
const int INF = 1e9 + 10;
int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a % b) ;
}
int lcm(int a, int b) {
    return a / gcd(a, b) * b;
}

int main(){
    int t;    scanf("%d", &t);
    while (t--) {
        int a, b, q;    scanf("%d%d%d", &a, &b, &q);
        int c;
        while (q--) {
            scanf("%d", &c);
            bool f = false;
            for(int j = 1; j <= 100; ++j) {
                if(j * a - c < 0)    continue;
                if((j * a - c) % b == 0)    f = true;
            }
            if(f)    puts("Yes");
            else    puts("No");
        }
    }
    return 0;
}


你可能感兴趣的:(线上比赛)