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 ...
随机推荐
- 【牛客网】数据库SQL实战(题解)
1.查找最晚入职员工的所有信息 [题解] hire_date可能存在重复值,所以需要找到hire_date的最大值,然后再筛选,才能hire_date最晚的记录都筛选出来. [代码] 1 SELECT ...
- DNA序列(JAVA语言)
package 第三章习题; /* * 输入m个长度均为n的DNA序列,求一个DNA序列,到所有序列的总Hamming距离尽量小. * 两个等长字符串的Hamming距离等于字符不同的位置个数, ...
- 【java框架】SpringBoot(4)--SpringBoot实现异步、邮件、定时任务
1.SpringBoot整合任务机制 1.1.SpringBoot实现异步方法 日常开发中涉及很多界面与后端的交互响应,都不是同步的,基于SpringBoot为我们提供了注解方式实现异步方法.使得前端 ...
- HashMap源码个人解读
HashMap的源码比较复杂,最近也是结合视频以及其余大佬的博客,想着记录一下自己的理解或者当作笔记 JDK1.8后,HashMap底层是数组+链表+红黑树.在这之前都是数组+链表,而改变的原因也就是 ...
- 《基于Kubernetes舵手集群的设计与实现》
前言 <基于Kubernetes舵手集群的设计与实现>是我的毕业设计项目.本系统采用Kubernetes容器编排.基于Jenkins\Gitlab的CICD技术.EFK日志收集.Prome ...
- SpringCloud LoadBalancer灰度策略实现
如何使用 Spring Cloud 2020 中重磅推荐的负载均衡器 Spring Cloud LoadBalancer (下文简称 SCL),如何扩展负载均衡策略? 你将从本文中获取到答案 快速上手 ...
- Android+Java Web+MySQL实现登录注册
1 前言&概述 这篇文章是基于此处文章的更新,更新了一些技术栈,更加贴近实际需要,以及修复了若干的错误. 这是一个前端Android+后端Java/Kotlin通过Servelt进行后台数据库 ...
- JavaFX+SpringBoot+验证码功能的小型薪酬管理系统
2020.07.22更新 1 概述 1.1 简介 一个简单的小型薪酬管理系统,前端JavaFX+后端Spring Boot,功能倒没多少,主要精力放在了UI和前端的一些逻辑上面,后端其实做得很简单. ...
- JPA简单的分页条件查询
1,service层代码: @Override public QrCodeRecordPaging getPage(String projectId, Integer pageNumber, Inte ...
- 【C】EM卡韦根32/24格式卡号转换的实现
写在前面 第八周实验报告的deadline马上就要到了,大家都在奋笔疾书.这次的实验报告中有一个十分秃然的任务,要求学生用C语言编写一段代码,来处理编码问题. 我的ddl是在第七周,所以较早地解决了这 ...