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

这次考得比较差

T1

本题我打了个 O ( n 2 ) O(n^2) O(n2)的暴力,
只拿了8.3分。
正解:递归

A C   C o d e AC~Code AC Code

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
int n,a,b,ans,v[9000010];
void dg(int dep,int w)
{
	if(v[dep]!=0||dep>n)
	  return;
	if(dep>ans)
	  ans=dep;
	v[dep]=1;
	dg(dep+a,w);     //吃水果
    dg(dep+b,w);
    if(w==0)
      dg(dep/2,1);    //喝水
}
int main()
{
    freopen("fruit.in","r",stdin);
    freopen("fruit.out","w",stdout);
    cin>>n>>a>>b;
    dg(0,0);
    cout<<ans;
    return 0;
}

T2

本题一眼过去就是二分答案
100 p t s 100pts 100pts
讲题好慌

A C   C o d e AC~Code AC Code

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
int a[100010];
int n,k,l,r=1e9,m;
inline bool check(int cow)
{
	int js=0;
	for(int i=1; i<=n;)
	 {
		int p=i++;
		js++;     //js是奶牛数
		while(a[i]-a[p]<=2*cow&&i<=n) //看当前奶牛最多摧毁多少干草包
		  i++;
	 }
	return js<=k;
}
int main()
{
	freopen("angry.in","r",stdin);
    freopen("angry.out","w",stdout);
	cin>>n>>k;
	for(int i=1; i<=n; i++) 
	   cin>>a[i];
	sort(a+1,a+n+1);
	while(l+1<r)         //二分
	 {
		m=l+r>>1;
		if(check(m))
		  r=m;
		else
		  l=m;
	 }
	if(check(l)) 
	  cout<<l;
	else
	  cout<<r;
	return 0;
}

T3

比赛时不会,
想打暴力的时候已经没时间了。
正解:DP

A C   C o d e AC~Code AC Code

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
int js[1010][1010],f[1010][1010],ti[100010],v[100010];
int t,n,m;
int main()
{
    freopen("interview.in","r",stdin);
    freopen("interview.out","w",stdout);
    cin>>t>>n>>m;
	for(int i=1; i<=n; i++)
	   cin>>ti[i]>>v[i];
	for(int i=1; i<=m; i++)
	 {
	 	cin>>js[i][0];
	 	for(int j=1; j<=js[i][0]; j++)
	 	   cin>>js[i][j];
	 }
	for(int i=1; i<=m; i++)
	 {
	 	for(int j=1; j<=t; j++)       //预处理
	 	   f[i][j]=f[i-1][j];
	 	for(int j=1; j<=js[i][0]; j++)
	 	 for(int k=t; k>=ti[js[i][j]]; k--)
	 	    f[i][k]=max(f[i][k],f[i-1][k-ti[js[i][j]]]+v[js[i][j]]);
	 }
	cout<<f[m][t];
    return 0;
}

T4

玄学骗分骗得 6.7 p t s 6.7pts 6.7pts
正解:bfs

A C   C o d e AC~Code AC Code

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
int v[1010][1010],ans[1010][1010];
int xw[1000010],yw[1000010];
int x,y,x2,y2,n,m,tj_ans;
int tot,hd[1010][1010];
int dx[5]={0,1,-1,0,0};
int dy[5]={0,0,0,1,-1};
struct node
{
	int tox,toy,next;
}e[1000010];
void ljb(int x,int y,int x2,int y2)
{ 
	e[++tot].tox=x2;
	e[tot].toy=y2;
	e[tot].next=hd[x][y];
	hd[x][y]=tot;
}
void bfs()
{
	int head=0,tail=1;
	ans[1][1]=1,v[1][1]=1;
	xw[1]=1,yw[1]=1;
	while(head<tail)
	 {
	 	head++;
	 	for(int i=hd[xw[head]][yw[head]];i;i=e[i].next)
	 	   ans[e[i].tox][e[i].toy]=1;     //加入答案
	 	for(int i=1; i<=head; i++)      //遍历
	 	 for(int j=1; j<=4; j++)
	 	  {
	 	  	int tx=xw[i]+dx[j],ty=yw[i]+dy[j];
	 	  	if(tx>=1&&tx<=n&&ty>=1&&ty<=n)
	 	  	 if(ans[tx][ty]==1&&v[tx][ty]==0)
	 	  	  {
	 	  	  	 tail++;
	 	  	  	 v[tx][ty]=1;     //标记位置
	 	  	  	 xw[tail]=tx;    //储存位置
	 	  	  	 yw[tail]=ty;
	 	  	  }
	 	  }
	 }
}
int main()
{
    freopen("light.in","r",stdin);
    freopen("light.out","w",stdout);
    cin>>n>>m;
    for(int i=1; i<=m; i++)
     {
     	cin>>x>>y>>x2>>y2;
     	ljb(x,y,x2,y2);
     }
    bfs();
    for(int i=1; i<=n; i++)
     for(int j=1; j<=n; j++)
      if(ans[i][j]==1)
        tj_ans++;
    cout<<tj_ans;
    return 0;
}

总分

8.7 + 100 + 0 + 6.3 = 115 p t s 8.7+100+0+6.3=115pts 8.7+100+0+6.3=115pts

总结

  1. 如果不会正解——暴力要打,骗分要骗
  2. 不要懒!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值