• 2019.6.20义乌测试赛自我成绩分析


    A. 平均分(average)

    • 提交程序:
    #include<bits/stdc++.h>
    using namespace std;
    int n,a;
    int sum=0;
    inline int read()
    {
    	int tot=0,f=1;
    	char c=getchar();
    	while(c<'0'||c>'9')
    	{
    		if(c=='-')f=-1;
    		c=getchar();
    	}
    	while(c>='0'&&c<='9')
    	{
    		tot=(tot<<1)+(tot<<3)+c-'0';
    		c=getchar();
    	}
    	return tot*f;
    }
    int main()
    {
    	n=read();
    	for(int i=1;i<=n;i++)
    		a=read(),sum+=a;
    	cout<<fixed<<setprecision(2)<<(double)sum/(double)n<<endl;
    	return 0;
    }       
    
    • 评测结果:

    Accepted 100分

    • 错误原因

    • 正确代码


    B.非降(nodown)

    • 提交程序:
    #include<bits/stdc++.h>
    using namespace std;
    char s[1000];
    int n;
    int main()
    {
    	scanf("%s",s+1);
    	n=strlen(s+1);
    	for(int i=2;i<=n;i++)
    	{
    		if(s[i]<s[i-1])
    		{
    			cout<<"No
    ";
    			return 0;
    		}
    	}
    	cout<<"Yes
    ";
    	return 0;
    }
    
    • 评测结果:

    Accepted 100分

    • 错误原因

    • 正确代码


    C.新魔法(new)

    • 提交程序:
    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int MAXN=100000+10;
    int n,k;
    ll a[MAXN];
    ll g[MAXN];
    ll ans=0;
    inline int read()
    {
    	int tot=0,f=1;
    	char c=getchar();
    	while(c<'0'||c>'9')
    	{
    		if(c=='-')f=-1;
    		c=getchar();
    	}
    	while(c>='0'&&c<='9')
    	{
    		tot=(tot<<1)+(tot<<3)+c-'0';
    		c=getchar();
    	}
    	return tot*f;
    }
    int main()
    {
    	n=read();k=read();
    	for(int i=1;i<=n;i++)
    	{
    		a[i]=read();
    		a[i]*=1000;
    		g[i]=g[i-1]+a[i];
    		//cout<<g[i]<<endl;
    	}
    	for(int i=k;i<=n;i++)
    	{
    		ans=max(ans,(g[i]-g[i-k])/k);
    	}
    	cout<<ans<<endl;
    	return 0;
    }
    
    • 评测结果:

    Accepted 100分

    • 错误原因

    • 正确代码


    D.排名(sort)

    • 提交程序:
    #include<bits/stdc++.h>
    using namespace std;
    const int MAXN=3000+10;
    int n;
    struct Node
    {
    	int sum;
    	int s;
    }a[MAXN];
    inline int read()
    {
    	int tot=0,f=1;
    	char c=getchar();
    	while(c<'0'||c>'9')
    	{
    		if(c=='-')f=-1;
    		c=getchar();
    	}
    	while(c>='0'&&c<='9')
    	{
    		tot=(tot<<1)+(tot<<3)+c-'0';
    		c=getchar();
    	}
    	return tot*f;
    }
    inline int get(int x)
    {
    	int tot=0;
    	while(x)
    	{
    		tot+=x%10;
    		x/=10;
    	}
    	return tot;
    }
    inline bool cmp(Node x,Node y)
    {
    	if(x.sum==y.sum)return x.s>y.s;
    	else return x.sum>y.sum;
    }
    int main()
    {
    	n=read();
    	for(int i=1;i<=n;i++)
    	{
    		a[i].s=read();
    		a[i].sum=get(a[i].s);
    		//cout<<a[i].s<<" "<<a[i].sum<<endl;
    	}
    	sort(a+1,a+1+n,cmp);
    	for(int i=1;i<=n;i++)
    		printf("%d
    ",a[i].s);
    	return 0;
    } 
    
    • 评测结果:

    Accepted 100分

    • 错误原因

    • 正确代码


    E.宿舍改建(build)

    • 提交程序:
    #include<bits/stdc++.h>
    using namespace std;
    const int MAXN=10000+10;
    int n,m,a;
    int w[MAXN];
    int cnt=0;
    inline int read()
    {
    	int tot=0,f=1;
    	char c=getchar();
    	while(c<'0'||c>'9')
    	{
    		if(c=='-')f=-1;
    		c=getchar();
    	}
    	while(c>='0'&&c<='9')
    	{
    		tot=(tot<<1)+(tot<<3)+c-'0';
    		c=getchar();
    	}
    	return tot*f;
    }
    int main()
    {
    	n=read();m=read();
    	for(int i=1;i<=n;i++)
    	{
    		a=read();
    		int pos=1;
    		while(pos<=cnt&&w[pos]+a>m)pos++;
    		if(pos>cnt)w[++cnt]=a;
    		else
    		{
    			w[pos]+=a;
    		}
    	}
    	cout<<cnt<<endl;
    	return 0;
    }       
    
    • 评测结果:

    Unaccepted 40分

    • 错误原因
    由于之前去华东吃饭大学参加了“游族杯”的比赛,其中有一题和这题非常非常非常相似,简直就是翻版(然而其实本质上是不一样的)。
    于是我就被洗脑了,一时没想到这题其实时一道很简单的二分题,而是用了一种奇奇怪怪的贪心来做
    
    • 正确代码
    #include<bits/stdc++.h>
    using namespace std;
    const int MAXN=10000+10;
    int n,m;
    int a[MAXN];
    int tt[MAXN];
    inline int read()
    {
        int tot=0,f=1;
        char c=getchar();
        while(c<'0'||c>'9')
        {
            if(c=='-')f=-1;
            c=getchar();
        }
        while(c>='0'&&c<='9')
        {
            tot=(tot<<1)+(tot<<3)+c-'0';
            c=getchar();
        }
        return tot*f;
    }
    inline bool check(int t)
    {
        for(int i=1;i<=t;i++)
            tt[i]=a[i];
        for(int i=t+1;i<=n;i++)
        {
            int minn=0x3f3f3f3f,pos=0;
            for(int j=1;j<=t;j++)//这一部分也可以用单调队列优化
                if(tt[j]<minn)minn=tt[j],pos=j;
            tt[pos]+=a[i];
            if(tt[pos]>m)return 0;
        }
        return 1;
    }
    int main()
    {
        n=read();m=read();
        for(int i=1;i<=n;i++)
            a[i]=read();
        int l=1,r=n,ans;
        while(l<=r)
        {
            int mid=l+r>>1;
            //cout<<l<<" "<<r<<" "<<mid<<" "<<check(mid)<<endl;
            if(check(mid))r=mid-1,ans=mid;
            else l=mid+1;
        }
        cout<<ans<<endl;
        return 0;
    }
    

    F.争霸赛(game)

    • 提交代码:
    #include<bits/stdc++.h>
    using namespace std;
    const int MAXN=2500+10;
    int n,k;
    int a[MAXN],b[MAXN];
    int cnt=0;
    inline int read()
    {
    	int tot=0,f=1;
    	char c=getchar();
    	while(c<'0'||c>'9')
    	{
    		if(c=='-')f=-1;
    		c=getchar();
    	}
    	while(c>='0'&&c<='9')
    	{
    		tot=(tot<<1)+(tot<<3)+c-'0';
    		c=getchar();
    	}
    	return tot*f;
    }
    int main()
    {
    	ios::sync_with_stdio(false);
    	//freopen("data2.in","r",stdin);
    	n=read();k=read();
    	char c;
    	for(int i=1;i<=n;i++)
    	{
    		a[i]=a[i-1];
    		b[i]=b[i-1];
    		cin>>c;
    		if(c=='H')a[i]++;
    		else b[i]++;
    		//cout<<a[i]<<" "<<b[i]<<endl;
    	}
    	int pos=n;
    	while(a[n]!=0||b[n]!=0)
    	{
    		bool flag=0;
    		//Sleep(100);
    		if(abs(a[pos]-b[pos])<=k||!a[pos]||!b[pos])
    		{
    			cnt++;
    			flag=1;
    		}
    		else pos--;
    		if(flag)
    		{
    			int x=a[pos],y=b[pos];
    			for(int i=pos;i<=n;i++)
    			{
    				a[i]-=x;
    				b[i]-=y;
    			}
    			pos=n;
    		}
    		/*cout<<pos<<" "<<flag<<" "<<cnt<<endl;
    		for(int i=1;i<=n;i++)cout<<a[i]<<" "<<b[i]<<endl;
    		cout<<endl;*/
    	}
    	cout<<cnt<<endl;
    	return 0;
    }
    
    • 评测结果:

    Unaccepted 30分

    • 错误原因:
    对于这题的30分,我感到十分恼火与悲哀,看到错误代码了吗?只要我把主函数里的"ios::sync_with_stdio(false)"给去掉,我就可以拿80分的高分!!!
    ios::sync_with_stdio(false)是关闭同步输入输出流的意思,在一定条件下可以加快读入数据的速度。
    值得一提的是:这个流氓一样的东西还是叶康杰教我们的,但却让我白白丢了50分TAT
    把这个东西去掉,还是只能拿80分,并拿不到满分,说明了贪心思想在本题是行不通的,要AC此题必须要进行DP
    
    • 正确代码:
    #include<bits/stdc++.h>
    using namespace std;
    const int MAXN=2500+10;
    int n,k;
    int a[MAXN],b[MAXN];
    int cnt=0;
    int dp[MAXN];
    inline int read()
    {
        int tot=0,f=1;
        char c=getchar();
        while(c<'0'||c>'9')
        {
            if(c=='-')f=-1;
            c=getchar();
        }
        while(c>='0'&&c<='9')
        {
            tot=(tot<<1)+(tot<<3)+c-'0';
            c=getchar();
        }
        return tot*f;
    }
    int main()
    {
        //freopen("data2.in","r",stdin);
        n=read();k=read();
        char c;
        dp[0]=0;
        for(int i=1;i<=n;i++)
        {
            a[i]=a[i-1];
            b[i]=b[i-1];
            cin>>c;
            if(c=='H')a[i]++;
            else b[i]++;
            //cout<<a[i]<<" "<<b[i]<<endl;
            dp[i]=i;
        }
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=i;j++)
            {
                int x=a[i]-a[j-1],y=b[i]-b[j-1];
                if(abs(x-y)<=k||!x||!y)dp[i]=min(dp[i],dp[j-1]+1);
            }
        }
        cout<<dp[n]<<endl;
        return 0;
    }
    
  • 相关阅读:
    深入理解浏览器的缓存机制
    【ES6】Set、Map、WeakSet 和 WeakMap 的区别
    js的防抖(debounce) 和 节流(throttling)
    git对比两个分支的差异——git checkout
    纯CSS实现可自定义间距虚线边框
    无语,非也
    Spring AOP
    Spring集成Junit
    Spring注解开发-新注解
    Spring注解开发-原始注解
  • 原文地址:https://www.cnblogs.com/hulean/p/11105839.html
Copyright © 2020-2023  润新知