2020.1.6 大一寒假集训最终测试(Contest)

Problem A:NEFU2101 28的因子

OJ里解除限制慎用。。指不定哪次就出玄学问题。
RE五次,最后以自暴自弃的心态删掉解除限制语句结果AC了。。

#include<bits/stdc++.h>
using namespace std;
int n;
int main()
{
	//ios::sync_with_stdio(false); //这行使得我RE了四次
    //这行到底敢不敢写,咱也不知道,咱也没地问
	//cout<<"AC!"<<endl;
	while(cin>>n)
    {
        int cnt4, cnt7;
        bool mark = false;
        cnt7 = n/7;
        for(int i=cnt7; i>=0; i--)
        {
            if((n-7*i)%4 == 0)
            {
                cnt4 = (n-7*i)/4;
                mark = true;
                cnt7 = i;
                break;
            }
        }
        if(!mark) cout<<"xinganheixiong"<<endl; //在下兴安灰熊
        else 
        {
            for(int i=1; i<=cnt4; i++)
                cout<<4;
            for(int i=1; i<=cnt7; i++)
                cout<<7;
            cout<<endl;
        }
    }
	return 0;
}

Problem B:NEFU2077 陈老师发奖金

结构体排序题,很简单。

#include<bits/stdc++.h>
using namespace std;
struct node{
    /* data */
    string xh;
    int cyy, yy, sx, sum, flag;
}cy[100086];
bool cmp(node x, node y)
{
    if(x.sum != y.sum) return x.sum>y.sum;
    else
    {
        if(x.yy != y.yy) return x.yy>y.yy;
        else
        {
            return x.flag>y.flag;
        }
    }
}
int main()
{
    ios::sync_with_stdio(false);
    int n;
    while(cin>>n)
    {
        for(int i=1; i<=n; i++)
        {
            cin>>cy[i].xh;
            cin>>cy[i].cyy>>cy[i].yy>>cy[i].sx;
            cy[i].sum = cy[i].cyy+cy[i].sx;
            cy[i].flag = i;
        }
        sort(cy+1, cy+n+1, cmp);
        if(n>4) n=4;
        for(int i=1; i<=n; i++)
            cout<<cy[i].xh<<" "<<cy[i].sum<<endl;
    }
    return 0;
}

Problem C:NEFU2096 小明分蛋糕

#include<bits/stdc++.h>
using namespace std;
int t, a, b, cake[15];
int query[15] = {0, 1, 1, 2, 2, 1, 2, 2, 3, 3, 2};
int main()
{
    ios::sync_with_stdio(false);
    cin>>t;
    while(t--)
    {
        int ans=0;
        cin>>a>>b;
        if(a == b)
        {
            cout<<"0"<<endl;
            continue;
        }
        int need = abs(b-a);
        for(int i=10; i>=1; i--)
        {
            cake[i] = need/i;
            need %= i;
        }
        for(int i=1; i<=10; i++)
            ans += cake[i]*query[i];
        cout<<ans<<endl;
    }
    return 0;
}

Problem D:NEFU2090 神奇的事情发生了

或许这就是栈叭,,,

//利用栈的思路
//s2作为栈
//s1元素依次入栈,并对O和o进行判断
#include<bits/stdc++.h>
using namespace std;
char s1[110], s2[110];
int main()
{
    ios::sync_with_stdio(false);
    while(cin>>s1)
    {
        int tot=0, n=strlen(s1);
        for(int i=0; i<n; i++)
        {
            s2[tot] = s1[i];
            
            if(s2[tot]=='o' && s2[tot-1]=='o')
            {
                s2[tot-1]='O';
                tot--;
            }
            if(s2[tot]=='O' && s2[tot-1]=='O')
            {
                tot-=2; //退两步,而不是退一步!!
            }
            tot++;
        }
        for(int i=0; i<tot; i++)
            cout<<s2[i];
        cout<<endl;
    }
    return 0;
}

Problem E:NEFU2083 jwMM选酒店

jwMM这梗是摘不掉了

#include<bits/stdc++.h>
using namespace std;
int n, k, p;
int pos = 0; // 最后遇到的小于等于最低消费的位置
long long sum = 0;
int num[55], color[200010];
int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>k>>p;
    for(int i=1; i<=n; i++) // 避免重复,假定i位置一定住
    {
        int pi;
        cin>>color[i]>>pi;
        if(pi <= p)
        {
            for(int j=pos+1; j<=i; j++)
                num[color[j]]++; //更新,到当前位置各个颜色的酒店数量
            pos = i; // 更新,离自己最近的奶茶店的位置
            sum += num[color[i]]-1; // 不能算自己
        }
        else sum += num[color[i]]; // 没有新增可供消费的奶茶店
    }
    cout<<sum<<endl;
    return 0;
}

听说洛谷有这么道题挺像的??
https://www.luogu.com.cn/problem/P1311
嗯?我怎么做对过呢?

Problem F:NEFU2078 jwMM的射箭游戏

被x2-y2不能为负坑惨

#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    long long x1, y1, x2, y2;
    while(cin>>x1>>y1>>x2>>y2)
    {
        bool flag=0;
        int t1=__gcd(x1, y1), t2=x2-y2;
        if(t2 <= 0) flag=0;
        else if(t1 == 1) flag=0;
        else if(__gcd(t1, t2) > 1)
            flag=1;
        if(flag)
            cout<<"Y"<<endl;
        else
            cout<<"N"<<endl;
    }
    return 0;
}

Problem G:NEFU2082 丹青玩游戏

做的时候直接让输入给整蒙了(套了两个结构体直接乱了),果断放弃。

#include<bits/stdc++.h>
using namespace std;
struct node{
    int k, p, num[15];
}li[15];
int n, m, light[15];
int main()
{
    ios::sync_with_stdio(false);
    while(cin>>n>>m)
    {
        int ans = 0;
        for(int i=0; i<m; i++)
        {
            cin>>li[i].k;
            for(int j=0; j<li[i].k; j++)
                cin>>li[i].num[j];
        }
        for(int i=0; i<m; i++)
            cin>>li[i].p;
        for(int i=0; i<(1<<n); i++)
        {
            bool flag=0, judge=0;
            memset(light, 0, sizeof(light));
            for(int j=0; j<n; j++)
                if(i&(1<<j))
                {
                    light[j+1] = 1;
                    //judge = 1;
                }
            for(int j=0; j<m; j++)
            {
                int cnt = 0;
                for(int t=0; t<li[j].k; t++)
                    if(light[li[j].num[t]])
                        cnt++;
                if(cnt%2 != li[j].p)
                {
                    flag = 1;
                    break;
                }
            }
            if(!flag) ans++;
        }
        cout<<ans<<endl;
    }
    return 0;
}

Problem H:NEFU2100 分糖果

#include<bits/stdc++.h>
using namespace std;
int n, m, t, a[200010];
int main()
{
    ios::sync_with_stdio(false);
    cin>>t;
    while(t)
    {
        int maxn = -1;
        cin>>n>>m;
        for(int i=0; i<n; i++)
        {
            cin>>a[i];
            a[i] %= m;
        }
        sort(a, a+n);
        for(int i=0; i<n; i++)
        {
            int x = m-a[i];
            x = lower_bound(a, a+n, x)-a;
            if(x-1 >= 0) // 防止越界
            {
                if(x-1 != i) // 如果前一位不是本身
                // 与前一位相加比较
                    maxn = max(a[i]+a[x-1], maxn);
                else if(x-2 >= 0) // 如果前一位是本身
                // 再往前一位相加比较
                    maxn = max(a[i]+a[x-2], maxn);
            }
            if(i != n-1) // 如果没有取到x为m-a[i]-1 -> 不是最优解
            // 与最后一个数相加比较
                maxn = max((a[i]+a[n-1])%m, maxn);
        }
        cout<<maxn<<endl;
        t--;
    }
    return 0;
}

Problem I:NEFU2088 抹发胶

#include<bits/stdc++.h>
using namespace std;
int t, n, a[110], b[110];
int main()
{
    ios::sync_with_stdio(false);
    cin>>t;
    while(t--)
    {
        cin>>n;
        memset(b, 0, sizeof(b));
        for(int i=1; i<=n; i++)
            cin>>a[i];
        for(int i=2; i<=n; i++)
        {
            for(int j=1; j<=i; j++)
                if(a[j] < a[i]) b[i]++;
        }
        for(int i=1; i<n; i++)
            cout<<b[i]<<" ";
        cout<<b[n]<<endl;
    }
    return 0;
}

Problem J:NEFU2085 天哥的难题

推导一下不难发现,快速幂取模问题。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll quick_pow(ll a, ll b, ll c)
{
	int rslt = 1;
	while(b)
	{
		if(b&1) rslt = rslt*a%c;
		a = a*a%c;
		b >>= 1;
	}
	return rslt;
}
int main()
{
    ios::sync_with_stdio(false);
    int m;
    while(cin>>m)
    {
        cout<<quick_pow(3, m, 1000000007)<<endl;
    }
    return 0;
}

Problem K:NEFU2084 煊哥的数字游戏

没想到推导过程这么麻烦,最后半小时净想这个去了。
甚至打了个表都没找到规律。

#include<bits/stdc++.h>
using namespace std;
int m, a[100100];
int main()
{
    ios::sync_with_stdio(false);
    long long sum=0, num=0;
    cin>>m;
    for(int i=1; i<=m; i++)
	{
	    cin>>a[i];
	    sum += a[i];
        num ^= a[i];
	}
    long long ti, sum0=sum;
    num *= 2;
    int i=0;
    while(sum != num)
    {
        ti = (long long)pow(2, i);
        if(sum%ti != num%ti)
        {
            sum += ti/2;
            num ^= ti;
        }
        i++;
    }
    if(i > 0) cout<<sum-sum0;
    else cout<<i;
    return 0;
}

Problem L:NEFU2102 吃辣条

jwMM送的签到题。一开始还被唬住了。

#include<bits/stdc++.h>
using namespace std;
int n, a[110];
int main()
{
    ios::sync_with_stdio(false);
    while(cin>>n)
    {
        for(int i=1; i<=n; i++)
            cin>>a[i];
        sort(a+1, a+n+1);
        cout<<a[n-1]<<" "<<a[2]<<endl;
    }
    return 0;
}
发布了58 篇原创文章 · 获赞 40 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/baidu_41248654/article/details/104137412