T1

CF1749B

题目描述

You are playing a computer game. To pass the current level, you have to kill a big horde of monsters. In this horde, there are nn monsters standing in the row, numbered from 11 to nn . The ii -th monster has a_iai​ health and a special "Death's Blessing" spell of strength b_ibi​ attached to it.

You are going to kill all of them one by one. It takes exactly hh seconds to kill a monster with health hh .

When the ii -th monster dies, it casts its spell that increases the health of its neighbors by b_ibi​ (the neighbors of the jj -th monster in the row are the monsters on places j - 1j−1 and j + 1j+1 . The first and the last monsters have only one neighbor each).

After each monster is killed, the row shrinks, so its former neighbors become adjacent to each other (so if one of them dies, the other one is affected by its spell). For example, imagine a situation with 44 monsters with health a = [2, 6, 7, 3]a=[2,6,7,3] and spells b = [3, 6, 0, 5]b=[3,6,0,5] . One of the ways to get rid of the monsters is shown below:

22 66 77 33 \xrightarrow{6\ s}6 s​ 88 1313 33 \xrightarrow{13\ s}13 s​ 88 33 \xrightarrow{8\ s}8 s​ 66 \xrightarrow{6\ s}6 s​ \{\}{} 33 66 00 55 33 00 55 33 55 55 The first row represents the health of each monster, the second one — the power of the spells.As a result, we can kill all monsters in 6 + 13 + 8 + 66+13+8+6 == 3333 seconds. Note that it's only an example and may not be the fastest way to get rid of the monsters.

What is the minimum time required to kill all monsters in the row?

输入格式

The first line contains a single integer tt ( 1 \le t \le 10^41≤t≤104 ) — the number of test cases.

The first line of each test case contains a single integer nn ( 1 \le n \le 2 \cdot 10^51≤n≤2⋅105 ) — the number of monsters in the row.

The second line contains nn integers a_1, a_2, \dots, a_na1​,a2​,…,an​ ( 1 \le a_i \le 10^91≤ai​≤109 ) — the initial health of corresponding monsters.

The third line contains nn integers b_1, b_2, \dots, b_nb1​,b2​,…,bn​ ( 0 \le b_i \le 10^90≤bi​≤109 ), where b_ibi​ is the strength of the spell for the ii -th monster.

It's guaranteed that the sum of nn doesn't exceed 2 \cdot 10^52⋅105 .

输出格式

For each test case, print one integer — the minimum possible total time to kill all monsters.

题意翻译

给定 n 个二元组 \{(a_i,b_i)\}{(ai​,bi​)}。

删除第 ii 个元素消耗 a_iai​ 秒,然后让相邻的二元组(注意,第 11 个和第 nn 个不相邻)的 a := a+b_ia:=a+bi​,求删除所有元素的最少时间。

输入输出样例

输入 #1复制

4
1
10
0
3
100 1 100
1 100 1
4
2 6 7 3
3 6 0 5
2
1000000000 1000000000
1000000000 1000000000

输出 #1复制

10
203
26
3000000000

说明/提示

In the first test case, there is only one monster that will be killed in 1010 seconds.

In the second test case, it's optimal to kill the first monster, the last monster and then the middle one. It will take 100 + 100 + (1 + 1 + 1)100+100+(1+1+1) == 203203 seconds.

In the third test case, it's optimal to kill the first monster, then the third one, then the fourth one and finally the second one. It will take 2 + 7 + (3 + 0) + (3 + 6 + 5)2+7+(3+0)+(3+6+5) == 2626 seconds.

贪心即可,b最高的怪留到最后解决即可。

#include<iostream>
#define ll long long
using namespace std;ll t,n,k,ans,max_;int main()
{cin>>t;while(t--){cin>>n;ans=0;max_=-1;for(int i=1;i<=n;i++){cin>>k;ans+=k;}for(int i=1;i<=n;i++){cin>>k;ans+=k;max_=max(max_,k); }cout<<ans-max_<<endl;}return 0;
}

T2

题目描述

stggstgg 忘记了自己的电脑密码,密码由 0-90−9 的四位数字组成, stggstgg 记得他的密码正好有两个不同的数字,而且每个数字在密码中恰好出现了两次, stggstgg 还能记住一些肯定没有使用过的数字,请你计算可能是 stggstgg 密码的所有组合的数量。

输入格式

输入一个 t(1 ≤ t ≤ 200)t(1≤t≤200) 代表测试数据组数

每个测试数据第一行输入一个整数 n(1 ≤ n ≤ 8)n(1≤n≤8) 为一定没使用的数字的个数

第二行输入 nn 个整数即一定没使用过的数字 (0 ≤ 每个数字 ≤ 9)(0≤每个数字≤9)

输出格式

每个数据输出一行为所有可能密码的组合数量

输入输出样例

输入 #1复制

2

8

0 1 2 4 5 6 8 9

1

8

输出 #1复制

6

216

组合数,直接套公式即可

#include<iostream>
#include<cstring>
using namespace std;int c(int n,int m);int f(int x);
int a[11],t,n,k;int main()
{cin>>t;memset(a,0,sizeof(a));a[0]=1;while(t--){cin>>n;for(int i=1;i<=n;i++)cin>>k;cout<<c(4,2)*c((10-n),2);}return 0;
}int c(int n,int m)
{return f(n)/f(n-m)/f(m);
}int f(int x)
{return a[x]>0?a[x]:a[x]=x*f(x-1);
}

T3

题目描述

给出一行 nn 个单元格,所有单元格最初都是白色的,我们可以使用一种印章,使相邻的两个单元格,其中一个变成红色,另一个变成蓝色,印章可以旋转,即可以将相邻的两个单元格染成 BRBR 或者 RBRB。

在使用的过程中,印章必须使用在 nn 个单元格上,不能使用在单元格以外的地方,印章可以多次使用于同一个单元格,单元格颜色以最后一次染色为准。

例如:如果我们想将单元格染成 BRBBWBRBBW ,我们需要将单元格 WWWWWWWWWW 进行如下操作:WWWWW→WWRBW→BRRBW→BRBBWWWWWW→WWRBW→BRRBW→BRBBW。

我们给出单元格最后染成的序列,请问,我们能否用印章,将全是白色的单元格序列进行零次或多次操作染成该序列?

输入格式

第一行包含一个整数 TT (1 ≤ T ≤ 1000)(1≤T≤1000) 测试用例的数量

每个测试用例的第一行包含一个整数 nn (1 ≤ n ≤ 1000)(1≤n≤1000) 单元格序列的长度

每个测试用例的第二行包含一个字符串 ss ,保证 ss 的长度为n,且只包含字母 B、R、WB、R、W ,分别表示蓝色,红色,白色的单元格。

输出格式

输出T行,每行对应测试用例的答案。

如果可能的话,输出“YESYES",否则输出“NONO”。

输入输出样例

输入 #1复制

12

5

BRBBW

1

B

2

WB

2

RW

3

BRB

3

RBB

7

WWWWWWW

9

RBWBWRRBW

10

BRBRBRBRRB

12

BBBRWWRRRWBR

10

BRBRBRBRBW

5

RBWBW

输出 #1复制

YES

NO

NO

NO

YES

YES

YES

NO

YES

NO

YES

NO

看见题目,手算了几个数据,发现只要连着的BR段R和B都有就可以,只需要处理连续的W即可,第一遍做的很复杂,string.find都用上了,没过也不知道原代码怎么改了。换了个思路,因为只需判断两个W之间的情况,为了避免特判,和初始末尾出问题,开头结尾都加上一个W,用r和b来标记R和B是否出现,如果都没出现,那就是连续的W,不用管直接continue即可,如果r和b只有一个为1,那说明有RB段不符合条件,直接ck=0,如果二者都为1,说明该区间符合,结束时把r和b都赋成0,判断下一个区间。最后通过ck判断是否能够构造出。

#include<iostream>
#include<cstring>
using namespace std;int t,n,ck,r,b;
string s;int main()
{cin>>t;while(t--){cin>>n>>s;ck=1;r=b=0;s="W"+s+"W";for(int i=0;i<=n+1;i++){if(s[i]=='W'){if(!r&&!b)continue;if(!r||!b)ck=0;if(r&&b) r=b=0;} if(s[i]!='W'){s[i]=='R'?r=1:b=1;}} cout<<(ck?"YES":"NO")<<endl;}return 0;
}

Week 1 训练赛相关推荐

  1. 2021年度训练联盟热身训练赛第四场 H - Rock Paper Scissors(字符串匹配,FFT)

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 2021年度训练联盟热身训练赛第四场 H - Rock Paper Scissors(字符串匹配,FF ...

  2. ACM训练赛--递推专题

    1001: Buy the Ticket Problem Description The "Harry Potter and the Goblet of Fire" will be ...

  3. 校内训练赛题解第三篇

    校内训练赛题解 人气估值 解题思路 脑力训练计划 (模拟 + 字符串) 解题思路 大暑赛期(贪心 + 思维) 人气估值 题目描述 你是某动画制作公司的企划部长.如今动画制作公司制作的东西,已经不仅仅局 ...

  4. DataFountain训练赛 | 用户逾期行为预测

    @Author:Runsen @Date:2020/9/2 为了把简历写的没那么难看,决定在搞定动态规划先,顺便搞一个简单训练赛,不然没有比赛,简历还真的不能过去. 信贷用户逾期预测是新手入门必备的一 ...

  5. 数据挖掘竞赛-北京PM2.5浓度回归分析训练赛

    北京PM2.5浓度回归分析训练赛 简介 DC上的一个回归题,比较简单. 时间原因没有细看,提交到70多名就结束了. 使用stacking方法结合多个回归模型. 过程 数据获取 官方给定. 数据探索 训 ...

  6. 数据挖掘竞赛-美国King County房价预测训练赛

    美国King County房价预测训练赛 简介 DC上的一个回归题(正经的回归题). 比较简单. 时间原因(暂时没什么时间看国内旧赛),看了一下网上的解答,改善了一下神经网络就提交了. 过程 数据获取 ...

  7. 数据挖掘竞赛-轴承故障检测训练赛

    轴承故障检测 简述 DC上的一个训练赛,简单的多分类问题.说实话,还是比较有意思的,虽然很多人正确率都达到了1(也就是测试集预测结果全过),但是如果训练集和测试集数据量加大,那么这个结果可能就不是这样 ...

  8. 训练不出结果_训练赛惨败SKT?FPX直播透露拿冠军原因!Karsa再谈离开RNG?

    都说人逢喜事精神爽,小凤凰拿了世界冠军当然更爽.一回国就开启了快乐直播,人均阴阳怪气,信息量巨大,让我们一起来康康吧! "刘青松赢了装自己很淡定,其实耳机里叫得最大声."" ...

  9. 【ECJTU_ACM 11级队员2012年暑假训练赛(8) - F - A Mame】

    Home Problems Status Contest Register Login B题要套一个数论的模版,注意m=1!! C题可以二分匹配,把行列看作点; 不能开百度,开谷歌搜题解,再次强调!一 ...

  10. CCF BDCI大赛急速报名,OneFlow四大训练赛题等你来战

    CCF大数据与计算智能大赛(CCF Big Data & Computing Intelligence Contest,简称CCF BDCI)由国家自然科学基金委员会指导,是大数据与人工智能领 ...

最新文章

  1. 计算机网络玩家需要掌握的八个DOS命令
  2. Zookeeper基于Java访问-权限模式
  3. centos eclipse java_CentOS7 安装 Eclipse
  4. 大文件上传 进度条显示(仿CSDN资源上传效果)
  5. 2025年单车平均搭载7-8颗!车载摄像头进入「前装」红利期
  6. 计算机及软件工程专业职称,有关软件工程师职称
  7. Python中文分词库jieba用法代码示例
  8. ETF基金定投策略回测分析
  9. Ubuntu下mysql的配置
  10. 疫情下的春招实习历程
  11. Javascript的事件驱动
  12. AD19 keepoutlayer相关
  13. 【天梯赛练习题(c语言)】
  14. [2019 年百度之星·程序设计大赛 - 初赛三]简要题解?
  15. MATLAB定态氢原子波函数可视化
  16. Threejs实现下雨,下雪,阴天,晴天,火焰
  17. 中国顶级门户网站架构分析1
  18. python在线编程免费课程-少儿编程网-Scratch_Python_教程_免费儿童编程学习平台
  19. com.netflix.discovery.DiscoveryClient - DiscoveryClient_UNKNOWN/
  20. java mahout使用教程_Mahout Java推荐引擎(一)

热门文章

  1. jquery实现audio的播放控制
  2. VideoView 无法播放此视频
  3. 移动端app设计开发经验之设计篇
  4. hive UDF 根据ip解析地理位置信息
  5. 图片轮播(现在手机app上常见的)
  6. 3DMAX一键屋顶建模插件MW RoofGen使用教程
  7. 【Vue】路由 —— 黑马程序员
  8. Beats 使用详解
  9. 豪华曹操传2014 (数据以及存档文件修改)
  10. 雅虎财经api_雅虎! 发布音乐API