Codeforces Round #379 (Div. 2) 总结分享

前言

  初入acm的新手,打算在cf混。这几天没有比赛,就做了个最新的Virtual participation。虽然说div2比较简单,但还是被虐得体无完肤。。。Orz。两个小时,共6道题。最后只AC了AB两道,花了20分钟,剩下的100分钟也不知道哪去了(逃



A、B两道水题没什么说的。那我们从C题开始吧:

C. Anton and Making Potions

  • 题意:

  制作n瓶药水,初始时每制作一瓶花费x秒,有两类法术,第一类(包含m个法术)使制作每瓶药的时间由x变为a[i] (a[i] < x) 并消耗b[i]点法力值,第二种(k个法术)能瞬间制造c[i]瓶并消耗d[i]点法力值,初始法力值为s,最多在两种类型中分别选一个法术来加快进度。求制作这n瓶药水最少花费的时间。

  • 思路:

  暴力法肯定爆时间O(m*k),所以没敢用,就去纠结各种“巧妙”的办法,然后。。。然后时间就过去了T.T    结束之后看Tutorial,第一类就暴力,第二类在第一类的基础上二分查找,这样O(m*log2k)就不会爆了。之前从未想过二分法查找近似数(如:找到比给定值小的最大元素),这里第二类本身是有序(非递减)的,正好用二分法。

  • 代码:

 1 #include <bits/stdc++.h>
 2
 3 using namespace std;
 4
 5 const int max_n = 1000000;
 6
 7 int n, m, k;
 8 int x, s;
 9 int a[max_n], b[max_n], c[max_n], d[max_n];
10
11 inline int max_complete(int mana_left)
12 {
13     int l = 0, r = k;
14     while (l < r)
15     {
16         int m = (l + r + 1) / 2;
17         if (d[m] <= mana_left) l = m; else r = m-1;
18     }
19     return c[l];
20 }
21
22 int main()
23 {
24     cin >> n >> m >> k;
25     cin >> x >> s;
26     a[0] = x;
27     b[0] = 0;
28     c[0] = 0;
29     d[0] = 0;
30     for (int i = 1; i <= m; i++) cin >> a[i];
31     for (int i = 1; i <= m; i++) cin >> b[i];
32     for (int i = 1; i <= k; i++) cin >> c[i];
33     for (int i = 1; i <= k; i++) cin >> d[i];
34     long long ans = 1LL * n * x;
35     for (int i = 0; i <= m; i++)
36     {
37         int mana_left= s - b[i];
38         if (mana_left< 0) continue;
39         ans = min(ans, 1LL * (n - max_complete(mana_left)) * a[i]);
40     }
41     cout << ans << endl;
42     return 0;
43 }

Unfold Code

  • 分析:

  虽然最大只有2e5,内存足够的情况下,max_n大一点更好,避免编程是改来改去的;

abcd[0]存放特殊元素,好处是使后续操作统一化(不必写额外语句去判断特殊情况);

数字的LL后缀代表这是一个long long型变量,1LL*int 使int变为long long(C语言基础,不同数据范围的运算,得到范围较大的类型);

最后就是二分法一定要好好写啊,考虑清楚再写,避免消耗过多时间。(这个二分法,搞了半小时....Orz);

时间: 2024-08-06 20:03:42

Codeforces Round #379 (Div. 2) 总结分享的相关文章

Codeforces Round #379 (Div. 2) Analyses By Team:Red &amp; Black

A.Anton and Danik Problems: 给你长度为N的,只含'A','D'的序列,统计并输出何者出现的较多,相同为"Friendship" Analysis: lucky_ji: 水题,模拟统计A和D的数目比较大小输出结果即可 Tags: Implementation B.Anton and Digits Problems: 给定k2个2,k3个3,k5个5及k6个6,可以组成若干个32或256,求所有方案中Sigma的最大值 Analysis: lucky_ji: 同

Codeforces Round #379(div 2)

A.B:=w= C: 题意: 你需要制作n瓶药水,每一瓶药水需要x秒. 你现在有m种A魔法,花费b[i],使得每一瓶药水的花费代价降为a[i],只能用一次. 有K种B魔法,花费d[i],使得瞬间制作好c[i]瓶药水,只能用一次. 你最多花费s的魔法值 问你最快完成要多少秒. 分析:题目所给的B魔法都是递增的,容易想到枚举用哪个A魔法,二分对应的B魔法,因为在MP充足的情况下,减少的药水越多对ans越有利 D: 题意:一个无限大的平面,给你一个King的位置,再给你其他棋子的位置,问你这个King

Codeforces Round #380 (Div. 2) 总结分享

B. Spotlights 题意 有n×m个格子的矩形舞台,每个格子里面可以安排一个演员或聚光灯,聚光灯仅可照射一个方向(俯视,上下左右).若聚光灯能照到演员,则称为"good position",求:共有多少"good position"(同一格子的不同照射方向算作不同的position). 思路 对于一行而言,只要分别找到两侧第一个演员的位置(命名"标志位"),就能确定这一行的"good position".两标志位以外的

Codeforces Round #379 (Div. 2) 解题报告

题目地址 本次CF是在今天早上深夜进行,上午有课就没有直接参加.今天早上上课坐到后排参加了virtual participation.这次CF前面的题目都非常的水,不到10分钟就轻松过了前两题,比较郁闷的是之后一直卡在C,开始是脑残的没有用二分TLE,后来又是因为一个常数打错而一直WA--于是模拟赛就只过了2道题(太弱了orz).时间到了后很快发现了脑残错误,终于A了C题.下午上完课回到宿舍看D题才发现D题水的不行,很快就A了.不过E和F就比较超出我现在知识范围了,暂时就先放下.第一次参加vir

Codeforces Round #379 (Div. 2) C. Anton and Making Potions(二分)

Anton is playing a very interesting computer game, but now he is stuck at one of the levels. To pass to the next level he has to prepare npotions. Anton has a special kettle, that can prepare one potions in x seconds. Also, he knows spells of two typ

Codeforces Round #379 (Div. 2) D. Anton and Chess(模拟)

Anton likes to play chess. Also, he likes to do programming. That is why he decided to write the program that plays chess. However, he finds the game on 8 to 8 board to too simple, he uses an infinite one instead. The first task he faced is to check

Codeforces Round #379 (Div. 2) E. Anton and Tree

题意:给你一棵树, 每个点要么是黑色要么是白色, 有一种操作是将同一个颜色的连通块变成相反的颜色,问你最少变换几次, 整颗树变成一种颜色. 思路: 缩点, 加求树的直径, 答案为树的直径除二向上取整. 1 #include<bits/stdc++.h> 2 #define LL long long 3 #define mk make_pair 4 using namespace std; 5 6 const int N = 5e5 + 7; 7 const int inf = 0x3f3f3f

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i