来暂时总结下这几天的CF专题吧…后续还会更新…

A - Ichihime and Triangle:

Ichihime is the current priestess of the Mahjong Soul Temple. She claims to be human, despite her cat ears.

These days the temple is holding a math contest. Usually, Ichihime lacks interest in these things, but this time the prize for the winner is her favorite — cookies. Ichihime decides to attend the contest. Now she is solving the following problem.

You are given four positive integers a, b, c, d, such that a≤b≤c≤d.

Your task is to find three integers x, y, z, satisfying the following conditions:

a≤x≤b.
b≤y≤c.
c≤z≤d.
There exists a triangle with a positive non-zero area and the lengths of its three sides are x, y, and z.
Ichihime desires to get the cookie, but the problem seems too hard for her. Can you help her?

Input
The first line contains a single integer t (1≤t≤1000) — the number of test cases.

The next t lines describe test cases. Each test case is given as four space-separated integers a, b, c, d (1≤a≤b≤c≤d≤109).

Output
For each test case, print three integers x, y, z — the integers you found satisfying the conditions given in the statement.

It is guaranteed that the answer always exists. If there are multiple answers, print any.

Example
Input
4
1 3 5 7
1 5 5 7
100000 200000 300000 400000
1 1 977539810 977539810
Output
3 4 5
5 5 5
182690 214748 300999
1 977539810 977539810

没啥好说的,就是输出b,c,c就行了…

B - Dawid and Bags of Candies

Dawid has four bags of candies. The i-th of them contains ai candies. Also, Dawid has two friends. He wants to give each bag to one of his two friends. Is it possible to distribute the bags in such a way that each friend receives the same amount of candies in total?

Note, that you can’t keep bags for yourself or throw them away, each bag should be given to one of the friends.

Input
The only line contains four integers a1, a2, a3 and a4 (1≤ai≤100) — the numbers of candies in each bag.

Output
Output YES if it’s possible to give the bags to Dawid’s friends so that both friends receive the same amount of candies, or NO otherwise. Each character can be printed in any case (either uppercase or lowercase).

Examples
Input
1 7 11 5
Output
YES
Input
7 3 2 5
Output
NO
Note
In the first sample test, Dawid can give the first and the third bag to the first friend, and the second and the fourth bag to the second friend. This way, each friend will receive 12 candies.

In the second sample test, it’s impossible to distribute the bags.

这道题主要是容易忽略掉3:1的情况,很多人只考虑到2:2,但是没有考虑到3:1
同时这两种不是else if 的关系,像我这么写是过不了的:

#include<iostream>
#include<algorithm>
using namespace std;
int a[4];
int main(){for(int i=0;i<4;i++)cin>>a[i];sort(a,a+4);if(a[3]+a[0]==a[1]+a[2])cout<<"YES"<<endl;else if(a[3]=a[0]+a[1]+a[2])cout<<"YES"<<endl;elsecout<<"NO"<<endl;
}

换做或语言就对了:

#include<iostream>
#include<algorithm>
using namespace std;
int a[4];
int main(){for(int i=0;i<4;i++)cin>>a[i];sort(a,a+4);if(a[3]+a[0]==a[1]+a[2]||a[0]+a[1]+a[2]==a[3])cout<<"YES"<<endl;elsecout<<"NO"<<endl;
}

C - Suits

A new delivery of clothing has arrived today to the clothing store. This delivery consists of a ties, b scarves, c vests and d jackets.

The store does not sell single clothing items — instead, it sells suits of two types:

a suit of the first type consists of one tie and one jacket;
a suit of the second type consists of one scarf, one vest and one jacket.
Each suit of the first type costs e coins, and each suit of the second type costs f coins.

Calculate the maximum possible cost of a set of suits that can be composed from the delivered clothing items. Note that one item cannot be used in more than one suit (though some items may be left unused).

Input
The first line contains one integer a (1≤a≤100000) — the number of ties.

The second line contains one integer b (1≤b≤100000) — the number of scarves.

The third line contains one integer c (1≤c≤100000) — the number of vests.

The fourth line contains one integer d (1≤d≤100000) — the number of jackets.

The fifth line contains one integer e (1≤e≤1000) — the cost of one suit of the first type.

The sixth line contains one integer f (1≤f≤1000) — the cost of one suit of the second type.

Output
Print one integer — the maximum total cost of some set of suits that can be composed from the delivered items.

Examples
Input
4
5
6
3
1
2
Output
6
Input
12
11
13
20
4
6
Output
102
Input
17
14
5
21
15
17
Output
325
Note
It is possible to compose three suits of the second type in the first example, and their total cost will be 6. Since all jackets will be used, it’s impossible to add anything to this set.

The best course of action in the second example is to compose nine suits of the first type and eleven suits of the second type. The total cost is 9⋅4+11⋅6=102.

简单的分情况的问题.用高级点的语言就是,使用贪心算法.判断e与f哪个大,大的就优先拿jackets去凑,然后再比较jacket与其他方案里面的其他物件谁更小,若jacket更小就直接输出e*d就行了,以此类推.看看代码吧,反正一次过.

#include<iostream>
#include<math.h>
using namespace std;
int main(){int a,b,c,d,e,f;cin>>a>>b>>c>>d>>e>>f;int min1=a>d?d:a;int min2=(b>c?c:b)>d?d:(b>c?c:b);if(e>f){if(min1==d)cout<<e*d<<endl;else{if((d-a)<=min2)cout<<a*e+(d-a)*f<<endl;elsecout<<a*e+min2*f<<endl;}}else{if(min2==d)cout<<f*d<<endl;else{if(d-min2<=min1)cout<<min2*f+(d-min2)*e<<endl;elsecout<<min2*f+e*min1<<endl;}}
}

D - Ania and Minimizing

У Ани есть большое число S. Десятичная запись этого числа состоит из n цифр и не содержит ведущих нулей. Аня может изменить не более k цифр в S. Она хочет это сделать так, чтобы S все еще не содержало ведущих нулей и было как можно меньше. Какое число получится у Ани в итоге?

Input
В первой строке записаны два целых числа n и k (1≤n≤200000, 0≤k≤n) — количество цифр в десятичной записи S и максимальное разрешенное количество измененных цифр

Во второй строке записано целое число S. Гарантируется, что S состоит ровно из n цифр и не содержит никаких ведущих нулей.

Output
Выведите минимальное возможное число S, которое может получиться у Ани. Обратите внимание, что у полученного числа должно быть ровно n цифр.

Examples
Input
5 3
51528
Output
10028
Input
3 2
102
Output
100
Input
1 1
1
Output
0
Note
A number has leading zeroes if it consists of at least two digits and its first digit is 0. For example, numbers 00, 00069 and 0101 have leading zeroes, while 0, 3000 and 1010 don’t have leading zeroes.

** 要使得这个输出最小,最好就是第一位为1,剩下的都尽量为0.因此算法就显而易见了.若第一个不为1,就让他变成1,剩下的不为0就让它变成0.**
** 但是我在做题的时候犯下了个致命错误,也许是以前的题目导致我的惯性思维,我误以为改变的数据是需要连在一起的,这导致我一直都AC不了.后面还是学长指点了才知道.
同时,还得注意n=1的情况,n=1的时候所有的数都要变成0,而不是1,这点也容易忘记.**

亮代码:

#include <iostream>
#include <string.h>
#include<string>
using namespace std;
string s;
int main()
{int n,k,i=0,j=0;cin>>n>>k>>s;for(i=0;i<n;i++){if(j<k&&k>0){if(s[0]!='1'&&i==0){s[i]='1';j++;}else if(i!=0&&s[i]!='0'){s[i]='0';j++;}if (n==1)s[i]='0';}else{break;}}cout<<s<<endl;
}

E - Emotes

There are n emotes in very popular digital collectible card game (the game is pretty famous so we won’t say its name). The i-th emote increases the opponent’s happiness by ai units (we all know that emotes in this game are used to make opponents happy).

You have time to use some emotes only m times. You are allowed to use any emotion once, more than once, or not use it at all. The only restriction is that you cannot use the same emote more than k times in a row (otherwise the opponent will think that you’re trolling him).

Note that two emotes i and j (i≠j) such that ai=aj are considered different.

You have to make your opponent as happy as possible. Find the maximum possible opponent’s happiness.

Input
The first line of the input contains three integers n,m and k (2≤n≤2⋅105, 1≤k≤m≤2⋅109) — the number of emotes, the number of times you can use emotes and the maximum number of times you may use the same emote in a row.

The second line of the input contains n integers a1,a2,…,an (1≤ai≤109), where ai is value of the happiness of the i-th emote.

Output
Print one integer — the maximum opponent’s happiness if you use emotes in a way satisfying the problem statement.

Examples
Input
6 9 2
1 3 3 7 4 2
Output
54
Input
3 1000000000 1
1000000000 987654321 1000000000
Output
1000000000000000000
Note
In the first example you may use emotes in the following sequence: 4,4,5,4,4,5,4,4,5.

简单题,将k个最大值和一个次大值作为一组,看看能循环多少次,循环不了的剩下的次数就全都用来发最大值的表情.

#include<iostream>
#include<algorithm>
using namespace std;
int a[1010000];
int main(){long long int n,m,k;cin>>n>>m>>k;for(int i=0;i<n;i++)cin>>a[i];sort(a,a+n);long long int b=m/(k+1);long long int c=m%(k+1);cout<<b*(k*a[n-1]+a[n-2])+c*a[n-1]<<endl;
}

F - Big Segment

A coordinate line has n segments, the i-th segment starts at the position li and ends at the position ri. We will denote such a segment as [li, ri].

You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all other ones. Now you want to test your assumption. Find in the given set the segment which covers all other segments, and print its number. If such a segment doesn’t exist, print -1.

Formally we will assume that segment [a, b] covers segment [c, d], if they meet this condition a ≤ c ≤ d ≤ b.

Input
The first line contains integer n (1 ≤ n ≤ 105) — the number of segments. Next n lines contain the descriptions of the segments. The i-th line contains two space-separated integers li, ri (1 ≤ li ≤ ri ≤ 109) — the borders of the i-th segment.

It is guaranteed that no two segments coincide.

Output
Print a single integer — the number of the segment that covers all other segments in the set. If there’s no solution, print -1.

The segments are numbered starting from 1 in the order in which they appear in the input.

Examples
Input
3
1 1
2 2
3 3
Output
-1
Input
6
1 5
2 3
1 10
7 10
7 7
10 10
Output
3

大意是找下有没有一个区间能够将所以区间全部包住,那就在输入的时候找下最大值与最小值,输入完后通过一次循环

CF专题(长安大学)相关推荐

  1. dp专题-cf 711c

    cf 711 c 题意:给出n颗树,初始有颜色,现在要涂颜色,只能对没有涂颜色的树上色,一棵树涂颜色有代价,现在要求,涂完颜色后,把n颗树划分成k个连续区间,每一个划分定义为相同颜色的连续区间,求k个 ...

  2. 专题三:bfs、图论专题(1.cf)

    其他 挑战程序设计竞赛 1.POJ 3259 Wormholes 这道题后来我又想了一个方法,只能说这个方法不是完全正确,还要因题而定.为什么这么说呢?我用的是Bellman-Ford找负圈,可以这么 ...

  3. CF进制转换专题进阶

    文章目录 168. Excel表列名称 进制转换 官方题解 171. Excel 表列序号 进制转换 483. 最小好进制 168. Excel表列名称 进制转换 题目链接 十进制转二十六进制数.不同 ...

  4. 数论与数学专题练习(一)(201802~201805)

    数论与数学专题练习(一)(201802~201805) 手动博客搬家: 本文发表于20180224 00:33:28, 原地址https://blog.csdn.net/suncongbo/artic ...

  5. 设计一个可以变换的c语言图案,关于图形和变换专题的数学试题

    关于图形和变换专题的数学试题 图形和变换训练试题(带答案) 一. 精心选一选(每题3分,共 30 分) 1.下列图中全等的图形是( ) 2.把一个正方形三次对折后沿虚线剪下, 如图所示: 则所得的图形 ...

  6. ad10捕捉pad中点_【中考专题】中点模型(通关篇)—三种方法,助你通关!

    线段中点是几何部分一个非常重要的概念,和后面学习的中线,中位线等概念有着密切的联系.在几何证明题中也屡次出现. 那么,如果在题中遇到中点你会想到什么? 等腰三角形三线合一:直角三角形斜边上的中线等于斜 ...

  7. 分布式专题(2)- 分布式 Java通信

    本篇一句话总结:Java实现分布式通信,可以基于Java API.开源框架和远程通信技术三种方式实现. 正文开始: 通过上一篇文章<分布式专题(1)- 计算机网络>我们知道了计算机之间之所 ...

  8. iOS CoreAnimation专题——实战篇(四)基于拖动手势的视图3D旋转效果

    二维图像的显示 矩阵变换 基向量 线性变换 线性变换的复合 平移变换 齐次坐标 齐次坐标下的点和向量的区别 齐次坐标下的平移变换 齐次坐标下的平行线相交问题 CATransform3D 基于CATra ...

  9. “离散元数值模拟仿真技术与应用”系列专题培训的通知

    各有关单位: 随着我国经济的发展,岩土工程涉及的要求从材料.理论到施工工艺都提出了全方位的系统升级.在岩土工程分析设计中,3DEC和PFC软件快速建模也一直是岩土工作者所关注的问题.3DEC是非连续岩 ...

最新文章

  1. 【Android】Retrofit 2.0 的使用
  2. Windows Server 2012改造成Windows8的方法(转载)
  3. iphone全部机型_苹果12,十三岁iPhone最鸡贼的一次发布会
  4. flux storm_Apache Storm:如何使用Flux配置KafkaBolt
  5. java mapper sql_Slardar Sql Mapper Framework for Java( Java 持久层框架一枚~)
  6. float数据在计算机内存中的存储方法
  7. rocketMq 顺序消费
  8. 【webpack系列】从零搭建 webpack4+react 脚手架(四)
  9. 【C语言项目设计】趣味算术游戏设计
  10. 华为开启管理员模式_华为设备管理员级别与其对应的权限
  11. 2020年10月24日=996 程序员节日快乐
  12. csv文件的格式---Comma Separate Values
  13. 控制仪表与计算机控制装置课程设计,控制仪表于装置课程设计报告
  14. VS2010如何安装MSComm控件
  15. conda create -n scrapy_spader python=3.6 报错CondaHTTPError
  16. centOS6.5中部署java调用h2o中python包环境
  17. 单样本的t检验(t-test)是什么?
  18. 仙剑java单机游戏_仙剑游戏源码(含文档)
  19. Android WIFI框架分析(1)
  20. GitHub release文件下载失败问题

热门文章

  1. memset(G, 0x3f, sizeof(G))涵义
  2. java爬虫 京东_教您使用java爬虫gecco抓取JD全部商品信息(一)
  3. LeetCode #77 组合
  4. 推断速度达seq2seq模型的100倍,谷歌开源文本生成新方法LaserTagger
  5. 北美票房排行榜 实时_快手直播丨主播实时直播监测数据分享——思文22号美妆童装专场...
  6. 你是我最想要的朋友——《天高地厚》
  7. Qt下的国际化方法—翻译文件(.ts .qm文件)的使用
  8. 网站正式上线之前的ICP备案和公安联网备案
  9. 程序员,请不要天天加班
  10. 计算机配置赛扬 奔腾,intel 赛扬、奔腾、酷睿哪个好?