【补】【暑假练习赛第一场】POJ 3278 、 HDU 1016、2089、1002、1155、5124

今天是集训的第三天、也开始了第一场训练赛。六个水题…三个小时,只A了4个,自己水平还是不行!

努力努力我要努力~我要每场都AK~


POJ 3278 Catch That Cow 【传送门】

大致题意:农夫抓牛,每次只能向右、向左、或者前进2倍的方向,问最少几次能抓到牛。

抽象成一条直线上两个点,农夫是变量farmer、牛是cow(奶牛)、然后farmer的只能 -1 +1 *2……就是三个方向,用BFS来解决问题!(以前有做过……)

#include<iostream>
#include<queue>
using namespace std;
 
typedef pair<int,int> point;
queue<point> que;
bool book[1000001]={false};
int next[3]={-1,1,2};
int n,k;
int minn=99999;
int main()
{
	cin >> n >> k;
	if(n==k)
		cout << "0\n";
	else
	{
		point p,p1;
		book[n]=true;
		p.first=n;
		p.second=0;
		que.push(p);
		bool flag=false;
		while(!que.empty())
		{
			p=que.front();
			que.pop();
			for(int i=0;i<3;i++)
			{
				int x;		
				if(i!=2)
					x=p.first+next[i];
				if(i==2)
					x=p.first*2;
	
				if(x>=0&&x<=100000&&book[x]==false)
				{
					book[x]=true;
					p1.first=x;
					p1.second=p.second+1;
					que.push(p1);	
				}
				if(x==k)
				{
					flag=true;
					break;
				}
			}
			if(flag)
				break;
		}
		p=que.back();
		cout << p.second << endl;
	}
 
	return 0;
}

HDU 1016 Prime Ring Problem 【传送门】

题目大意:有一个大于0小于n的数字n,组成了一个“素数圈”要求,以数字1为开头,要求首尾相接,左右相邻数字之和必须是负数,给定终点n,求满足以上条件的所有集合。

很明显的一道深搜的题目,以数字1开头,然后终点是n,深搜的终止条件是数组长度==n,循环条件是从2到n并且最后一个数字与第一个数字之和为负数;如果数字没有在结果数组,并且向左相加数字为负数,则把该数字加入数组,标记为已经取过了。然后调用深搜就可以了。

坑:每一组数据最后一个数字之后都没有空格,导致我贡献好几次PE。

#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<stack>
using namespace std;

int n;
bool prime[40];
bool s[20];
int dig[25],top;

void prepare()
{
	prime[1]=true;
	prime[2]=true;
	prime[3]=true;
	prime[5]=true;
	prime[7]=true;
	prime[11]=true;
	prime[13]=true;
	prime[17]=true;
	prime[19]=true;
	prime[23]=true;
	prime[29]=true;
	prime[31]=true;
	prime[37]=true;	
}

void dfs()
{
	if(top==n+1&&prime[dig[1]+dig[top-1]]==true)
	{
		for(int i=1;i<top-1;i++)
			cout << dig[i] << " ";
		cout << dig[top-1];
		cout << endl;
		return;
	}
	for(int i=2;i<=n;i++)
	{
		//是质数 
		if(prime[dig[top-1]+i]==true && s[i]==false)
		{
			s[i]=true;
			//Sta.push(i);
			dig[top++]=i;
			dfs();
			s[i]=false;
			top--;
		}	
	}	
}

int main()
{
	int cnt=0;
	memset(prime,false,sizeof(prime));

	prepare();
	while(cin >> n)
	{
		top=1;
		memset(s,false,sizeof(s));
		s[1]=true;
		dig[1]=1;
		top++;
		cout << "Case "<< ++cnt << ":\n";
		dfs();
		cout << endl;
	}
	
	return 0;
	
}

HDU 2089 不要62 【传送门】

这道题目我是直接暴力打表了……更快的方法要用数位dp做,可是昨天没有怎么听懂。。理解了之后一定来补上!

#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<stack>
using namespace std;
#define MAXN 1000001

bool flag[MAXN];

void prepare()
{
	memset(flag,false,sizeof(flag));
	
	for(int i=1;i<MAXN;i++)
	{
		int temp=i;
		while(temp)
		{
			if(temp%10==4||temp%100==62)
			{
				flag[i]=true;
				break;
			}
			temp/=10;
		}
	}
}

int main()
{
	
	prepare();
	
	int n,m;
	while(cin >> n >> m && n && m)
	{
		int ans=0;
		for(int i=n;i<=m;i++)
		{
			if(flag[i])
				ans++;
		}
		
		cout << m-n+1-ans << endl;
		
	}
	return 0;
	
}

HDU 1002 A+B problem2 【传送门】

#include<iostream>
#include<string>
#include<vector>
using namespace std;
 
int main()
{
	int T;
	scanf("%d",&T);
	int k=1;
	while(T--)
	{
		string a,b,a1,b1;
		vector<int> sum;
		if(k>1) printf("\n");
		cin >> a >> b;
		a1=a;b1=b;
		printf("Case %d:\n",k++);
		if(a.size()>b.size())
		{
			b.insert(0,a.size()-b.size(),48);
			//cout << b;
		}
		if(a.size()<b.size())
		{
			a.insert(0,b.size()-a.size(),48);
		//	cout << a;
		}
		
		for(int i=a.size()-1;i>=0;i--)
		{
			int total=a.at(i)+b.at(i)-48*2;
			if(total<10)
			{
				//cout << total <<endl;
				sum.push_back(total);
			}
			else
			{
				sum.push_back(total%10);
				if(i!=0)
					a.at(i-1)+=total/10;
				if(i==0)
					sum.push_back(total/10);
			}
		}
	
		cout << a1 <<" + "<< b1 << " = ";
		for(int i=sum.size()-1;i>=0;i--)
			printf("%d",sum[i]);
		printf("\n");
		//if(k!=T) printf("\n");
	}
	return 0;
 } 

HDU 1155 Bungee Jumping 【传送门】

题目大意:一个特工在迫不得已的情况下要跳悬崖,有一根绳子,给了绳子强度K,绳子长度L,悬崖高S,特工体重W,如果绳子过长速度过快特工会摔死、如果绳子过短特工会漂浮在空中、还有一种情况就是速度不太快正好能在特工能够承受的速度下安全落地。然后给了一堆文科生看不懂的物理公式(不禁要问一句这谁顶的住啊!!),让求特工跳崖后的三种状态。

当时我看到这个题的时候就凉凉了,因为作为一个文科生我是真的不知道什么重力加速度、动能公式什么乱七八糟的东西……其实我知道这个题的原理是很简单的……可是这谁顶的住啊……

//https://www.cnblogs.com/syhandll/p/4786249.html(转)

先码下来上面的博客……待我多学会儿物理,再回来解决问题!!


HDU 5124 lines 【传送门】

……………………留着补题!!!


ACM简直虐死我了!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值