Codeforces Round #694 (Div. 2)

1 #include<iostream>
2 #include<algorithm>
3 #include<cstring>
4 #include<cstdio>
5 #include<cmath>
6 using namespace std;
7 const int maxx=1e5+10;
8 int main(){
9 int t;
10 scanf("%d",&t);
11 while(t--){
12 int n,x;
13 scanf("%d %d",&n,&x);
14 int a[maxx]={0};
15 long long int sum=0,y=0,summ=0;
16 for(int i=0;i<n;i++){
17 scanf("%d",&a[i]);
18 sum+=(a[i]/x);
19 if(a[i]%x!=0){
20 sum++;
21 }
22 summ+=a[i];
23 }
24 long long int mi=0,ma=0;
25 if(summ%x!=0){
26 mi++;
27 }
28 mi+=summ/x;
29 printf("%lld %lld\n",mi,sum);
30 }
31 }
B. Strange List
题意:设当前数为q,如果q能被x整除,在序列末端插入x个q/x,q移到下一位元素重复以上操作,如果不能就结束操作。求序列最终的和。
思路:其实这个是有规律的,插入x个q/x就是加q,只要q能被x整除就加q,一直到出现一个不能被x整除的数为止。也就是说,即使加入了x个q/x,那么和加q没什么区别
当时没想到的:1)本想着用数组,然后手写动态的数组,进行n++,然后存储空间太小,爆掉了;2)然后就想着要不要用队列,然后发现还是爆掉了;3)这种会RE或者会TLE的题目一定有简单的解法,一个是进行找找规律
代码:

1 #include<iostream>
2 #include<algorithm>
3 #include<cstdio>
4 #include<cstring>
5 #include<cmath>
6 #include<queue>
7 using namespace std;
8 const long long int maxx=1e7;
9 long long int a[maxx];
10 long long int b[maxx];
11 int main(){
12 long long int t;
13 scanf("%lld",&t);
14 while(t--){
15 long long int n,x;
16 scanf("%lld %lld",&n,&x);
17 long long int sum=0;
18 queue<int> s;
19 for(long long int i=0;i<n;i++){
20 scanf("%lld",&a[i]);
21 b[i]=a[i];
22 sum+=a[i];
23 }
24 int flag=0;
25 while(!flag){
26
27 for(int i=0;i<n;i++){
28 if(b[i]%x){
29 flag=1;
30 break;
31 }
32 sum+=a[i];
33 b[i]/=x;
34 }
35
36 }
37 printf("%lld\n",sum);
38 }
39 }
C. Strange Birthday Party
题意:p有n位朋友,每位朋友有一个数ki。商店有m份礼物,第j份礼物价值cj美元,每份礼物只能买一次。当j<=ki时,p要么给第i位朋友价值为cj的礼物,要么直接给cki美元。问最小花费。
思路:注意c序列升序。对k序列降序处理,k值大的先选,避免较小的k值拿走较小的c值,最小值从c1开始,每次和cki比较取较小值。因为一个是第二个数组肯定是升序,这样的话,为了增大c中对应的cki和ci之间的差别,就应该倒置,因为c数组一定是从小到大
代码:

1 #include<iostream>
2 #include<algorithm>
3 #include<cstdio>
4 #include<cstring>
5 #include<cmath>
6 #include<queue>
7 using namespace std;
8 const long long int maxx=3e5+10;
9 int a[maxx];
10 int b[maxx];
11 int main(){
12 long long int t;
13 scanf("%lld",&t);
14 while(t--){
15 int n,m;
16 scanf("%d %d",&n,&m);
17 for(int i=0;i<n;i++){
18 scanf("%d",&a[i]);
19 }
20 for(int i=0;i<m;i++){
21 scanf("%d",&b[i]);
22 }
23 int p=0;
24 sort(a,a+n);
25 int s=b[p++];
26 long long int sum=0;
27 for(int i=n-1;i>=0;i--){
28 if(b[a[i]-1]>s){
29 sum+=s;
30 s=b[p++];
31
32 }else{
33 sum+=b[a[i]-1];
34
35 }
36
37 }
38
39 printf("%lld\n",sum);
40 }
41 }
Codeforces Round #694 (Div. 2)的更多相关文章
- Codeforces Round #433 (Div. 2)【A、B、C、D题】
题目链接:Codeforces Round #433 (Div. 2) codeforces 854 A. Fraction[水] 题意:已知分子与分母的和,求分子小于分母的 最大的最简分数. #in ...
- Codeforces Round #292 (Div. 1)A. Drazil and Factorial 构造
A. Drazil and Factorial 题目连接: http://codeforces.com/contest/516/problem/A Description Drazil is play ...
- B. Ohana Cleans Up(Codeforces Round #309 (Div. 2))
B. Ohana Cleans Up Ohana Matsumae is trying to clean a room, which is divided up into an n by n gr ...
- B. The Number of Products(Codeforces Round #585 (Div. 2))
本题地址: https://codeforces.com/contest/1215/problem/B 本场比赛A题题解:https://www.cnblogs.com/liyexin/p/11535 ...
- Codeforces Round #517 (Div. 2)(1~n的分配)
题:https://codeforces.com/contest/1072/problem/C 思路:首先找到最大的x,使得x*(x+1)/2 <= a+b 那么一定存在一种分割使得 a1 &l ...
- Codeforces Round #805 (Div. 3)E.Split Into Two Sets
题目链接:https://codeforces.ml/contest/1702/problem/E 题目大意: 每张牌上面有两个数字,现在有n张牌(n为偶数),问能否将这n张牌分成两堆,使得每堆牌中的 ...
- 贪心+构造( Codeforces Round #344 (Div. 2))
题目:Report 题意:有两种操作: 1)t = 1,前r个数字按升序排列: 2)t = 2,前r个数字按降序排列: 求执行m次操作后的排列顺序. #include <iostream&g ...
- Codeforces Round #516 (Div. 2)D. Labyrinth(BFS)
题目链接:http://codeforces.com/contest/1064/problem/D 题目大意:给你一个n*m的图,图中包含两种符号,'.'表示可以行走,'*'表示障碍物不能行走,规定最 ...
- Codeforces Round #281 (Div. 2) A. Vasya and Football 模拟
A. Vasya and Football 题目连接: http://codeforces.com/contest/493/problem/A Description Vasya has starte ...
随机推荐
- css导航条的设计
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="U ...
- 利用flex解决input定位的问题
用简单的布局搞定input框使用fixed下输入的问题 最近在做移动端H5聊天应用发现,当input框在最底部并且使用 position:fixed 属性的时候在苹果手机中会出现不兼容的情况
- Git标签与别名
code[class*="language-"], pre[class*="language-"] { color: rgba(51, 51, 51, 1); ...
- 浅析MyBatis(四):全自动写代码的MyBatis逆向工程
在前面几篇文章中,笔者介绍了 MyBatis 的运行流程,在此基础上简单介绍了手写 MyBatis 简易框架与自定义 MyBatis 插件的步骤,相信大家对于 MyBatis 框架的使用流程已经游刃有 ...
- 运维小姐姐说这篇Consul集群和ACL配置超给力(保姆级)
前言 上一篇简单介绍了Consul,并使用开发模式(dev)进行流程演示,但在实际开发中需要考虑Consul的高可用和操作安全性,所以接着来聊聊集群和ACL的相关配置,涉及到的命令会在环境搭建过程中详 ...
- [源码解析] 并行分布式框架 Celery 之架构 (2)
[源码解析] 并行分布式框架 Celery 之架构 (2) 目录 [源码解析] 并行分布式框架 Celery 之架构 (2) 0x00 摘要 0x01 上文回顾 0x02 worker的思考 2.1 ...
- 一文搞懂如何实现 Go 超时控制
为什么需要超时控制? 请求时间过长,用户侧可能已经离开本页面了,服务端还在消耗资源处理,得到的结果没有意义 过长时间的服务端处理会占用过多资源,导致并发能力下降,甚至出现不可用事故 Go 超时控制必要 ...
- 全网最详细的Linux命令系列-cd命令
Linux cd 命令可以说是Linux中最基本的命令语句,其他的命令语句要进行操作,都是建立在使用 cd 命令上的. 所以,学习Linux 常用命令,首先就要学好 cd 命令的使用方法技巧. 命令格 ...
- shell分支与循环结构
1. 条件选择 1.1 条件判断分支介绍 格式 if COMMANDS; then COMMANDS; [ elif COMMANDS; then COMMANDS; ]... [ else COMM ...
- 后端Spring Boot+前端Android交互+MySQL增删查改
2021.1.27 更新 已更新新版本博客,更新内容很多,因此新开了一篇博客,戳这里. 1 概述 使用spring boot作为后端框架与Android端配合mysql进行基本的交互,包含了最基本的增 ...