A. Strange Partition
题意:就是求最小和最大的bi/x向上取整的和。
思路:见题解:https://blog.csdn.net/qq_45900709/article/details/112341661
当时没想到的:就是不是说能够代替,不应该是平均以后再向上取整吗,尤其是等式的后一部分
代码:

 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)的更多相关文章

  1. Codeforces Round #433 (Div. 2)【A、B、C、D题】

    题目链接:Codeforces Round #433 (Div. 2) codeforces 854 A. Fraction[水] 题意:已知分子与分母的和,求分子小于分母的 最大的最简分数. #in ...

  2. Codeforces Round #292 (Div. 1)A. Drazil and Factorial 构造

    A. Drazil and Factorial 题目连接: http://codeforces.com/contest/516/problem/A Description Drazil is play ...

  3. 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 ...

  4. 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 ...

  5. Codeforces Round #517 (Div. 2)(1~n的分配)

    题:https://codeforces.com/contest/1072/problem/C 思路:首先找到最大的x,使得x*(x+1)/2 <= a+b 那么一定存在一种分割使得 a1 &l ...

  6. Codeforces Round #805 (Div. 3)E.Split Into Two Sets

    题目链接:https://codeforces.ml/contest/1702/problem/E 题目大意: 每张牌上面有两个数字,现在有n张牌(n为偶数),问能否将这n张牌分成两堆,使得每堆牌中的 ...

  7. 贪心+构造( Codeforces Round #344 (Div. 2))

    题目:Report 题意:有两种操作: 1)t = 1,前r个数字按升序排列:   2)t = 2,前r个数字按降序排列: 求执行m次操作后的排列顺序. #include <iostream&g ...

  8. Codeforces Round #516 (Div. 2)D. Labyrinth(BFS)

    题目链接:http://codeforces.com/contest/1064/problem/D 题目大意:给你一个n*m的图,图中包含两种符号,'.'表示可以行走,'*'表示障碍物不能行走,规定最 ...

  9. Codeforces Round #281 (Div. 2) A. Vasya and Football 模拟

    A. Vasya and Football 题目连接: http://codeforces.com/contest/493/problem/A Description Vasya has starte ...

随机推荐

  1. maven-plugin-shade 详解

    一.介绍 [1] This plugin provides the capability to package the artifact in an uber-jar, including its d ...

  2. Git代码版本控制流程

    我们的项目使用Git作为代码仓库.和版本控制工具. Git有几种Workflow,来管理代码版本变更流程,我们采用Gitflow Workflow流程. Gitflow Workflow,采用了mas ...

  3. Python3基础之构建setup.py

    技术背景 在上一篇博客中,我们介绍了如何使用pyinstaller将python项目打包成一个可执行文件,并且放在系统目录下,让系统用户可以直接识别到我们构造的项目.而python项目中常见的setu ...

  4. 【linux】驱动-8-一文解决设备树

    目录 前言 8. Linux设备树 8.1 设备树简介 8.2 设备树框架 8.2.1 设备树格式 8.2.1.1 DTS 文件布局 8.2.1.2 node 格式 8.2.1.3 propertie ...

  5. C++并发与多线程学习笔记--async、future、packaged_task、promise

    async future packaged_task promise async std:async 是个函数,用来启动一个异步任务,启动起来一个异步任务之后,返回一个std::futre对象,启动一 ...

  6. C#委托的学习了解

    C#的委托(Delegate)类似于C\C++的函数指针.委托是存有对某一个方法引用的一种引用变量类型,引用可在运行时被改变. 委托特别用于实现事件和回调方法.所有的委托都派生自System.Dele ...

  7. OO_Unit 3 JML规格化设计总结

    OO_Unit 3 JML规格化设计总结 JML语言概述(Level 0) 概念定义   JML(Java Modeling Language)是用于对Java程序进行规格化设计的一种表示语言.JML ...

  8. 深入了解springcloud gateway 的限流重试机制

    前言 前面给大家介绍了Spring Cloud Gateway的入门教程,这篇给大家探讨下Spring Cloud Gateway的一些其他功能. Spring Cloud Gateway中的重试 我 ...

  9. 聊聊 OAuth 2.0 的 Token 续期处理

    Token 校验逻辑 // CheckTokenEndpoint.checkToken @RequestMapping(value = "/oauth/check_token") ...

  10. 我与Git的那些破事(上)--代码管理

    1. Git是什么? 作为一名程序猿,我相信大家都或多或少接触过git--分布式版本控制软件. 有人说,它是目前世界上最先进的分布式版本控制系统,我想说,是否最先进不知道,但确实好用,实用. 作为一款 ...