3.30训练题

首先说一下这套题的反思:1细节错误反复犯,

            2读题不认真,看不到操作做多只有一次,

            3数组开的不够,

            4做题时不知道拿纸笔推导,导致与正解擦肩而过

            5盲目自信

综上所述:我就是个弟弟

A

A - Sasha and His Trip
题意:给你两个小于等于100的数, n和v, 要从1号城市花最少的钱到n号城市, 汽车最大油箱油量是v, 每移动一格都花费1的油 第i号城市单位油价是i

这道题要是粗心大意地乍一看感觉像是个比价复杂的问题,但是只要稍微一分析就知道是个贪心,在后面加油肯定不如在前面加省钱,所以我们尽可能在前面加。但是由于油箱容量的限制,我们最开始只能加v单位的油,之后,每走一格加一次,因为只有一空我就加,在前面加肯定比留着到后面去加要优。可是本弱这么写完之后就wa了,看着队友一个个多a了,百思不得其解到底哪里错了,我真傻,真的。我是在开始的时候给ans赋值为v,这样的话就一定要注意如果n<=v,那么ans=n-1就可以了。当然如果换一种写法,从二到n遍历,每走一格,如果这一格的距离终点小于v,那么花费为1(在一开始就加上了),否则花费为i,就可以避免我得这个问题了。

代码:

#include<iostream>
#include<cstdio>
using namespace std;
int n,v;
int ans;
int main()
{
	cin>>n>>v;
	ans=v;
	for(int i=2;i+v<=n;++i)ans+=i;
	if(v>n-1)ans=n-1;
	printf("%d",ans);
	return 0;
}

 BOne day Sasha visited the farmer 2D and his famous magnetic farm. On this farm, the crop grows due to the influence of a 

special magnetic field. Maintaining of the magnetic field is provided by n machines, and the power of the i-th machine is ai.

This year 2D decided to cultivate a new culture, but what exactly he didn't say. For the successful growth of the new culture,
it is necessary to slightly change the powers of the machines. 2D can at most once choose an arbitrary integer x, then choose
one machine and reduce the power of its machine by x times, and at the same time increase the power of one another machine by
x times (powers of all the machines must stay positive integers). Note that he may not do that if he wants. More formally, 2D
can choose two such indices i and j, and one integer x such that x is a divisor of ai, and change powers as following:
ai=aix
, aj=aj⋅x Sasha is very curious, that's why he wants to calculate the minimum total power the farmer can reach. There are too many
machines, and Sasha can't cope with computations, help him!

  题目大意就是在一个序列里找一个数,他除以他的因子,让另一个乘以他的因子,然后让整个序列和变得最小,求最小的序列和。注意这样的操作只能做一次。所以

猜你喜欢

转载自www.cnblogs.com/yuelian/p/12602451.html