2017年浙江工业大学大学生程序设计迎新赛预赛

这套题终于补完了。。。 嗨森阿

A

这是一个很简单的Nim游戏的博弈问题

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <bitset>
 
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<int, int>
#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);
        int ans = 0;
        for (int i = 0; i < n; ++i) {
            scanf("%d", num + i);
            ans ^= num[i];
        }
        if (ans == 0 || (num[k - 1] < (num[k - 1] ^ ans))) {
            puts("No");
        } else {
            puts("Yes");
        }
    }
    return 0;
}



B

关键在于处理表达式,注意x + x这种情况

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <bitset>
 
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<int, int>
#define mst(a, b)   memset(a, b, sizeof a)
#define REP(i, x, n)    for(int i = x; i <= n; ++i)
const int MOD = 1000000007;
const int qq = 1e5 + 10;
const int INF = 1e9 + 10;
string st;
map<LL, LL> mp;
LL ct = 0;
void get(int &i) {
    LL a, b, tmp = 1;
    a = b = 0;
    if (st[i] == '-')   tmp = -1, ++i;
    else if (st[i] == '+')  ++i;
    if (st[i] == 'x') {
        a = tmp * 1;
    } else if (isdigit(st[i])) {
        while (isdigit(st[i])) {
            a = a * 10 + st[i++] - '0';
        }
        a = a * tmp;
    }
    if (st[i] == 'x') {
        i++;
        if (st[i] == '^') {
            i++;
            while (isdigit(st[i])) {
                b = b * 10 + st[i++] - '0';
            }
        } else {
            b = 1;
        }
    }
    if (mp.find(b) == mp.end()) {
        mp[b] = a;
    } else {
        mp[b] += a;
    }
}
LL quickPow(LL a, LL b) {
    LL ans = 1;
    while (b > 0) {
        if (b & 1)  ans = (ans * a) % MOD;
        a = (a * a) % MOD;
        b >>= 1;
    }
    return ans;
}
 
int main(){
    ios::sync_with_stdio(false);
    while (cin >> st) {
        int len = st.size(), i = 0;
        while (i < len) {
            get(i);
        }
        map<LL, LL>::iterator it;
        int t;  cin >> t;
        while (t--) {
            LL x;   cin >> x;
            x %= MOD;
            LL ans = ct;
            for (it = mp.begin(); it != mp.end(); ++it) {
                ans = (ans + (it->second * (quickPow(x, it->first)) % MOD + MOD) % MOD + MOD) % MOD;
            }
            cout << ans << endl;
        }
        mp.clear();
        ct = 0;
    }
    return 0;
}


C

处理其中的映射关系,预处理前n项的阶乘,注意要求逆元

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <bitset>
 
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<int, int>
#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 fin[qq];
LL quickPow(LL a, LL b) {
    LL ans = 1;
    while (b > 0) {
        if(b & 1)   ans = (ans * a) % MOD;
        b >>= 1;
        a = (a * a) % MOD;
    }
    return ans;
}
void Init() {
    fin[0] = 1;
    for (int i = 1; i < qq; ++i) {
        fin[i] = (1LL * i * fin[i - 1]) % MOD;
    }
}
map<LL, LL> mp;
LL num[qq];
LL n, m;
void solve(LL a, LL b) {
    a = mp[a];
    LL ans = (fin[b] * quickPow((fin[a] * fin[b - a]) % MOD, MOD - 2) ) % MOD;
    printf("%lld\n", num[(ans % n) + 1]);
}
int main(){
    Init();
    int t;  scanf("%d", &t);
    while (t--) {
        mp.clear();
        scanf("%lld%lld", &n, &m);
        for (int i = 1; i <= n; ++i) {
            scanf("%lld", num + i);
            mp[num[i]] = i;
        }
        while (m--) {
            LL a, b;    scanf("%lld%lld", &a, &b);
            solve(a, b);
        }
    }
    return 0;
}


D

代码写的比较蠢,直接用的双端队列模拟的

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <bitset>
 
using namespace std;
#define LL
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值