纪中2020.2.13普及C组模拟赛总结

嗯,不出意料又炸了T1比赛的时候就是看不懂题比赛后发现就是个冒泡排序!?AC Code:AC~Code:AC Code:#include<iostream>#include<cstdio>#include<cmath>using namespace std;int n,a[1110],b[1110],z,ans,w[1110...
摘要由CSDN通过智能技术生成

嗯,不出意料又炸了

T1

比赛的时候就是看不懂题
比赛后发现就是个冒泡排序!?

A C   C o d e : AC~Code: AC Code:

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int n,a[1110],b[1110],z,ans,w[1110];
int main()
{
	freopen("laundry.in","r",stdin);
    freopen("laundry.out","w",stdout);
    cin>>n;
    for(int i=1; i<=n; i++)
       cin>>a[i]>>b[i];
    for(int i=1; i<=n; i++)
     for(int j=1; j<=n; j++)
      if(a[i]==b[j])
        w[i]=j;
    for(int i=1; i<=n-1; i++)     //冒泡排序
	 for(int j=1; j<=n-i; j++)
	  if(w[j]>w[j+1])
	   {
	      z=w[j];
	      w[j]=w[j+1];
	      w[j+1]=z;
	      ans++;
	   }
    cout<<ans;
    return 0;
}

T2

感觉自己比赛时打的代码是对的,
但是只得了 40 p t s 40pts 40pts
赛后也不知道自己原来错哪儿了,
但其实正解很简单
前缀和一下就好了。

A C   C o d e AC~Code AC Code

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int n,p,c,a[1110],cpn;
int f[1110],ans;
int main()
{
	freopen("meet.in","r",stdin);
    freopen("meet.out","w",stdout);
    cin>>n>>p>>c;
    for(int i=1; i<=n; i++)
     {
     	cin>>cpn;
     	a[cpn+1]++;
     }
    for(int i=1; i<=p; i++)
       f[i]=f[i-1]+a[i];
    for(int i=1; i<=p; i++)
     for(int j=1; j<=p; j++)
      {
      	 if(f[i]-f[j]<=c)
      	   ans=max(ans,i-j);
      }
    cout<<ans;
    return 0;
}

T3

比赛时打了个暴力
错了

正解:模拟!(差点AC)

A C   C o d e AC~Code AC Code

#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
long long head,tail,ans;
long long l,r,n;
char c;
struct node
{
	long long l,r;
}a[110010];
bool cmp(const node&k,const node&l)
{
	return ((k.l<l.l)||(k.l==l.l)&&(k.r<l.r));
}
int main()
{
	freopen("paint.in","r",stdin);
	freopen("paint.out","w",stdout);
	cin>>n;
	for(int i=1; i<=n; i++)
	 {
		cin>>l>>c;
		if(c=='R')
		  l=r-l;
		else 
		  l=r+l;
		a[i].l=min(l,r);
		a[i].r=max(l,r);
		r=l;
	 }
	sort(a+1,a+1+n,cmp);
	head=a[1].l;
	tail=a[1].r;
	for(int i=2; i<=n; i++)
	 {
		if(a[i].r<head)continue;
		if(a[i].r<=tail)
		 {
			ans=ans+a[i].r-max(a[i].l,head);
			head=a[i].r;
		 }
		else if(a[i].l>tail)
		 {
			head=a[i].l;
			tail=a[i].r;
		 }
		else if(a[i].l<head)
		 {
			ans=ans+tail-head;
			head=tail;
			tail=a[i].r;
		 }
		else
		 {
			ans=ans+tail-a[i].l;
        	head=tail;
        	tail=a[i].r;
		 }
	 }
	cout<<ans;
	return 0;
}

T4

这道题可称之为 d f s dfs dfs模板题
比赛时漏了个判断
0 p t s 0pts 0pts

A C   C o d e AC~Code AC Code

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int dx[5]={0,1,0,-1,0};
int dy[5]={0,0,1,0,-1};
int n,b[6][6],a[6][6],l=1,r;
int ans;
char c;
void dfs(int x,int y,int l,int r)
{
	if(l==r)
	 {
	 	if(l*2>ans)
	 	  ans=l+r;
	 	return;
	 }
	for(int i=1; i<=4; i++)
	 {
	 	if(x+dx[i]>0&&x+dx[i]<=n&&y+dy[i]>0&&y+dy[i]<=n&&b[x+dx[i]][y+dy[i]]==0)
	 	 {
	 	 	b[x+dx[i]][y+dy[i]]=1;
	 	 	if(a[x+dx[i]][y+dy[i]]==1&r==0)
	 	  	  dfs(x+dx[i],y+dy[i],l+1,r);
	 	    if(a[x+dx[i]][y+dy[i]]==0)
	 	  	  dfs(x+dx[i],y+dy[i],l,r+1);
	 	    b[x+dx[i]][y+dy[i]]=0;
	 	 }

	 }
}
int main()
{
	freopen("hshoe.in","r",stdin);
    freopen("hshoe.out","w",stdout);
    cin>>n;
    for(int i=1; i<=n; i++)
     for(int j=1; j<=n; j++)
      {
      	cin>>c;
      	if(c==')')
      	  a[i][j]=0;
      	if(c=='(')
      	  a[i][j]=1;
      }
    if(a[1][1]==0)
     {
     	cout<<0;
     	return 0;
     }
    b[1][1]=1;
    dfs(1,1,1,0);
    cout<<ans;
    return 0;
}

总分

0 + 40 + 0 + 0 = 40 p t s 0+40+0+0=40pts 0+40+0+0=40pts

总结

  1. 审题要细心,要不然会酿成大错;
  2. 做题不能急,一急就完蛋;
  3. 时间应该主要分配在有把握的题上。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值