AtCoder Beginner Contest 189

B - Alcoholic /
Time Limit: 2 sec / Memory Limit: 1024 MB

Score :
200
points

Problem Statement
Takahashi had
N
glasses of liquor.

The amount and alcohol percentage of the
i
-th liquor were
V
i
milliliters and
P
i
percent by volume, respectively.

Takahashi gets drunk when his alcohol intake exceeds
X
milliliters.

Which of the
N
liquors was he drinking when he gets drunk? If he was not drunk even after drinking all the liquors, print -1 instead.

Constraints
All values in input are integers.
1

N

10
3
0

X

10
6
1

V
i

10
3
0

P
i

100
Input
Input is given from Standard Input in the following format:

N

X

V
1

P
1

V
N

P
N

Output
If Takahashi got drunk when drinking the
i
-th liquor, print
i
. If he was not drunk even after drinking all the liquors, print -1 instead.

Sample Input 1
Copy
2 15
200 5
350 3
Sample Output 1
Copy
2
The
1
-st liquor contains
200
×
5
100

10
milliliters of alcohol.

The
2
-nd liquor contains
350
×
3
100

10.5
milliliters of alcohol.

His alcohol intake exceeds
15
milliliters for the first time when drinking the
2
-nd liquor.

Sample Input 2
Copy
2 10
200 5
350 3
Sample Output 2
Copy
2
When his alcohol intake is exactly
X
milliliters, he is still not drunk.

Sample Input 3
Copy
3 1000000
1000 100
1000 100
1000 100
Sample Output 3
Copy
-1
He seems to be immune to alcohol.

当我们发现有精度问题的话,我们面对除法没有办法的时候,我们可以把除法转变为乘法,这样可以避免精度问题

#include<iostream>
 
using namespace std;
const int N=1e3+10;
 
int a[N], b[N];
 
int main()
{
    int n,x;
    cin>>n>>x;
    x*=100;
    long long sum=0;
    for(int i=1;i<=n;i++)
    {
        int l,r;
        scanf("%d%d",&l,&r);
        a[i]=l*r;
    }
    
    for (int i = 1; i <= n; i ++)   b[i] = 123;
    
    int ans=-1;
    for(int i=1;i<=n;i++)
    {
        sum+=a[i];
        if(sum>x)
        {
            ans=i;
            break;
        }
    }
    
    for (int i = 1; i <= n; i ++)   b[i] = i - 1;
    
    printf("%d\n",ans);
    return 0;
}

C - Mandarin Orange
Problem Statement
There are
N
dishes arranged in a row in front of Takahashi. The
i
-th dish from the left has
A
i
oranges on it.

Takahashi will choose a triple of integers
(
l
,
r
,
x
)
satisfying all of the following conditions:

1

l

r

N
;
1

x
;
for every integer
i
between
l
and
r
(inclusive),
x

A
i
.
He will then pick up and eat
x
oranges from each of the
l
-th through
r
-th dishes from the left.

At most how many oranges can he eat by choosing the triple
(
l
,
r
,
x
)
to maximize this number?

Constraints
All values in input are integers.
1

N

10
4
1

A
i

10
5
Input
Input is given from Standard Input in the following format:

N

A
1

A
N

Output
Print the maximum number of oranges Takahashi can eat.

Sample Input 1
Copy
6
2 4 4 9 4 9
Sample Output 1
Copy
20
By choosing
(
l
,
r
,
x
)

(
2
,
6
,
4
)
, he can eat
20
oranges.

Sample Input 2
Copy
6
200 4 4 9 4 9
Sample Output 2
Copy
200
By choosing
(
l
,
r
,
x
)

(
1
,
1
,
200
)
, he can eat
200
oranges.

找到一段区间最小值的个数的乘积的最大值

当我们面对超时得问题,如果我们可以少一重循环的话,我们便可以过,少一重循环的第一个办法是把重复计算的数放到外面,每次使用的时候沿着之前的继续走,第二个方式是改变枚举的东西,一般来说,哪个值比较小,我们就枚举哪个东西,或者来说,我们想在循环中更新什么值,可以影响我们循环的东西,也许最简单的循环顺序正是最简单的

#include<iostream>
 
using namespace std;
 
const int N=1e4+10;
 
int a[N], b[N];
 
int main()
{
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    
    for (int i = 1; i <= n; i ++)   b[i] = 1039;
    
    for(int i=1;i<=n;i++)
    {
        int minv=1e7;
        for(int j=i;j<=n;j++)
        {
            minv=min(minv,a[j]);
            ans=max(ans,minv*(j-i+1));
        }
    }
    
    for (int i = 1; i <= n; i ++)   b[i] = i - 1;
    
    cout<< ans <<endl;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值