第四周 周结(贪心&DP)

训练内容:

SDAU19训练-贪心&DP4
题目链接:https://vjudge.net/contest/362443

本周训练感悟:

没提过2020的疫情,转眼间疫情快要结束了,估计也快要到开学的时候了,在家又上网课又刷题,眼睛都快瞎了。日常焦虑,似乎焦虑是因为打比赛做不出几个题来吧,训练内容有的超级简单,有的思路很复杂,确实想不出来,有搜题解去认真理解,有的确实是因为题目都不明白比如下面的题目I就没读懂题目,主要还是英语不好,翻译工具也翻译不明白,所以啊,码农对英语也还是很高要求的啊,恶补英语ing……

题目整理:
I - Standard Free2play

You are playing a game where your character should overcome different obstacles. The current problem is to come down from a cliff. The cliff has height h, and there is a moving platform on each height x from 1 to h.

Each platform is either hidden inside the cliff or moved out. At first, there are n moved out platforms on heights p1,p2,…,pn. The platform on height h is moved out (and the character is initially standing there).

If you character is standing on some moved out platform on height x, then he can pull a special lever, which switches the state of two platforms: on height x and x−1. In other words, the platform you are currently standing on will hide in the cliff and the platform one unit below will change it state: it will hide if it was moved out or move out if it was hidden. In the second case, you will safely land on it. Note that this is the only way to move from one platform to another.

Your character is quite fragile, so it can safely fall from the height no more than 2. In other words falling from the platform x to platform x−2 is okay, but falling from x to x−3 (or lower) is certain death.

Sometimes it’s not possible to come down from the cliff, but you can always buy (for donate currency) several magic crystals. Each magic crystal can be used to change the state of any single platform (except platform on height h, which is unaffected by the crystals). After being used, the crystal disappears.

What is the minimum number of magic crystal you need to buy to safely land on the 0 ground level?

Input
The first line contains one integer q (1≤q≤100) — the number of queries. Each query contains two lines and is independent of all other queries.

The first line of each query contains two integers h and n (1≤h≤109, 1≤n≤min(h,2⋅105)) — the height of the cliff and the number of moved out platforms.

The second line contains n integers p1,p2,…,pn (h=p1>p2>⋯>pn≥1) — the corresponding moved out platforms in the descending order of their heights.

The sum of n over all queries does not exceed 2⋅105.

Output
For each query print one integer — the minimum number of magic crystals you have to spend to safely come down on the ground level (with height 0).

Example
Input
4
3 2
3 1
8 6
8 7 6 5 3 2
9 6
9 8 5 4 3 1
1 1
1
Output
0
1
2
0
题意:在一个高度为h的山上每个高度都有台阶, 其中有n个台阶显示出来,其他都是闭上的,只有显示的能跳,但每跳到一个台阶下一个高度的台阶状态就会变换(注意不是下一个显示的台阶,而是下一个高度x+1)闭上的打开,打开的闭上,如果跳到比原来大于2个距离就会死,每次魔法可以改变某个台阶的状态,问不死跳到底最少需要多少次魔法。
题目理解:个人是根据样例画的图 大概就是相邻的如果都显示出来就可以连跳两个到x+2,如果不相邻就要使用一个魔法让这个x和x+1的状态交换(其实是这个x缩进去x+1改变状态,因为前面判断了不相邻所以其实就是x和x+1状态交换,你可以试着画一画)交换之后就可以调到x+1了,接下来就是重复以上操作了,,,(但是根据样例是这么回事,但好像还是没太懂题目叭 觉得有些地方没太懂 搜题解也没太懂,先这样理解吧 以后在考虑别的思路)

#include <iostream>
#include<cmath>
using namespace std;
const int N=2e5+7;
int n,m,a[N];
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int ans=0;
        cin>>n>>m;
        for(int i=1; i<=m; i++)
            cin>>a[i];
        a[m+1]=0;
        for(int i=2; i<=m; i++)
        {
            if(a[i]==a[i+1]+1)
            {
                i++;
                continue;
            }
                ans++;
        }
        cout<<ans<<endl;
    }
}

再加一个之前就做过但这次又错了好几次的题,刷题不能盲目啊…………

P - Product of Three Numbers

You are given one integer number n. Find three distinct integers a,b,c such that 2≤a,b,c and a⋅b⋅c=n or say that it is impossible to do it.

If there are several answers, you can print any.

You have to answer t independent test cases.

Input
The first line of the input contains one integer t (1≤t≤100) — the number of test cases.

The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2≤n≤109).

Output
For each test case, print the answer on it. Print “NO” if it is impossible to represent n as a⋅b⋅c for some distinct integers a,b,c such that 2≤a,b,c.

Otherwise, print “YES” and any possible such representation.

Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823
题意很简单就是给你一个数让你随便找三个不同的数相乘等于这个数;
我第一次做这个题的时候想的就是三重循环,但是没通过,请教了学长知道了是因为三重循环的复杂度太高,运行会超时;所以改变想法就是让n也加入进寻找乘数的运算里面,找到第一个可以被n整除的数就选择这个数,并让n等于n除以这个数的结果,再继续寻找能被n整除的数,但是这个数不能是之前的数也不能n除以这个数还是这个数 更不能n就等于这个数因为选的数不能是1;最后第三个数就是n在除以选的第二个数就可以了 ,这样一层循环就OK了。

#include<iostream>
#include<cmath>
using namespace std;
long long n,t,k,x1,x2;
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n;
		k=pow(n,1.0/2);
		x1=0;
		x2=0;
		int flag=0;
		for(int i=2;i<=k;i++)
		{
			if(n%i==0)
			{
				if(x1==0)
				{
					x1=i;
					n/=i;
				}
				else
				{
					if(x1*i!=n&&i*i!=n&&n!=i)
					{
						x2=i;
						n/=i;
						flag=1;
						break;
					}
				}
			}
		}
		if(flag==1)
		{
			cout<<"YES"<<endl;
			cout<<x1<<" "<<x2<<" "<<n<<endl;
		}
		else
		{
			cout<<"NO"<<endl;
		}
	}
}

Nothing is impossible!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值