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

挺不错的一套题 写了几道鸽了没写完 有空继续补

比赛链接 https://www.nowcoder.com/acm/contest/52#question

A.

尼姆博弈的想法 很久没写题了 博弈都忘完了 看了提示 其实很简单,,,

#include <bits/stdc++.h>
using namespace std;
#define LL long long
const int MAXN = 1e5+10;
int main()
{
    ios::sync_with_stdio(false);
    int T; cin >>T;
    while (T--) {
        int n, k, x, y; cin >> n >> k;
        int res = 0;
        for(int i = 1; i <= n; i++) {
            cin >> x;
            if(k == i) {
                y = x; continue;
            }
            res ^= x;
        }
        if(res < y) cout << "Yes\n";
        else cout << "No\n";
    }
return 0;
}

B. 多项式求值

感觉这个题好zz啊 就是个简单的快速幂 非要 用字符串读入 而且是多组输入 debug到崩溃QAQ

#include <bits/stdc++.h>
using namespace std;

#define LL long long
const LL mod = 1e9+7;
const LL MAXN = 1e6+100;
char str[MAXN];
LL len;
LL pwo_mod(LL a, LL b)
{
    LL ans = 1; a %= mod;
    while(b) {
        if(b&1) ans = (ans*a)%mod;
        a = (a*a)%mod;
        b >>= 1;
    }
    return ans;
}
LL get_num(LL l, LL r)
{
    LL num = 0, res = 1;
    for(LL i = r; i >= l; i--) {
        num += res*(str[i]-'0');
        res *= 10;
    }
    return num;
}
LL calcu(LL a, LL b, LL x)
{
    LL res = 1ll*a*pwo_mod(x,b)%mod;
    return res;
}
bool is_num(LL x)
{
    if(str[x]>='0' && str[x]<='9') return true;
    return false;
}
void solve(LL x)
{
    LL ans = 0;
    LL a, b, l, r;
    LL clr;
    for(LL i = 0; i < len; i++) {
        if(str[i] == '-') clr = -1;
        else clr = 1;
        if(str[i]=='+' || str[i]=='-') i++;
        l = r = i;
        if(str[l] == 'x') {
            a = 1, b = 1; l--, r--;
        }
        else {
            while(r+1<len && is_num(r+1)) r++;
            a = get_num(l,r); b = 1;
        }
        if(str[r+1] != 'x') {
            b = 0; i = r;
        }
        else if(str[r+2] == '^') {
            l = r+3, r = l;
            while(r+1<len && is_num(r+1)) r++;
            b = get_num(l,r); i = r;
        }
        else i = r+1;
        ans = (ans+clr*calcu(a,b,x))%mod;
    }
    ans = (ans%mod+mod)%mod;
    printf("%lld\n",ans);
}
int main()
{
    while(~scanf("%s",str)) {
        LL x, m;
        len = strlen(str);
        scanf("%lld",&m);
        while(m--) {
            scanf("%lld",&x); solve(x);
        }
    }


return 0;
}

C. 数的变换

数学相关 有空在补

这里写代码片

D. 简单的数据结构

用deque写下就好 list超时mmp

#include <bits/stdc++.h>
using namespace std;
#define LL long long
const int MAXN = 1e5+10;
int main()
{
    ios::sync_with_stdio(false);
    int n, m, x, y;
    deque<int> d;
    cin >> n >> m;
    while(m--) {
        cin >> x;
        if(x == 1) {
            cin >> y; d.push_front(y);
        }
        if(x == 2) {
            d.pop_front();
        }
        if(x == 3) {
            cin >> y; d.push_back(y);
        }
        if(x == 4) {
            d.pop_back();
        }
        if(x == 5) {
            reverse(d.begin(),d.end());
        }
        if(x == 6) {
            cout << d.size() << endl;
            for(int i = 0; i < d.size()-1; i++) cout << d[i] << ' ';
            cout << d[d.size()-1] << "\n";
        }
        if(x == 7) {
            sort(d.begin(),d.end());
        }
    }

return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值