A. Search for Pretty Integers
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given two lists of non-zero digits.

Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer?

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 9) — the lengths of the first and the second lists, respectively.

The second line contains n distinct digits a1, a2, ..., an (1 ≤ ai ≤ 9) — the elements of the first list.

The third line contains m distinct digits b1, b2, ..., bm (1 ≤ bi ≤ 9) — the elements of the second list.

Output

Print the smallest pretty integer.

Examples
input
2 3
4 2
5 7 6
output
25
input
8 8
1 2 3 4 5 6 7 8
8 7 6 5 4 3 2 1
output
1
Note

In the first example 25, 46, 24567 are pretty, as well as many other integers. The smallest among them is 25. 42 and 24 are not pretty because they don't have digits from the second list.

In the second example all integers that have at least one digit different from 9 are pretty. It's obvious that the smallest among them is 1, because it's the smallest positive integer.

水题

#include<bits/stdc++.h>
using namespace std;
const int MAX = ;
int main()
{
int n,m,a[MAX],b[MAX],ans=,i,j;
cin>>n>>m;
for(i=;i<=n;i++) cin>>a[i];
for(i=;i<=m;i++) cin>>b[i];
sort(a+,a++n);
sort(b+,b++m);
for(i=;i<=n;i++)
for(j=;j<=m;j++)
{
if(a[i]==b[j])ans=min(ans,a[i]);
}
if(ans==)
{
int u=max(a[],b[]),v=min(a[],b[]);
ans=u+v*;
}
cout<<ans<<endl;
}
B. Maximum of Maximums of Minimums
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given an array a1, a2, ..., an consisting of n integers, and an integer k. You have to split the array into exactly k non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the k obtained minimums. What is the maximum possible integer you can get?

Definitions of subsegment and array splitting are given in notes.

Input

The first line contains two integers n and k (1 ≤ k ≤ n ≤  105) — the size of the array a and the number of subsegments you have to split the array to.

The second line contains n integers a1,  a2,  ...,  an ( - 109  ≤  ai ≤  109).

Output

Print single integer — the maximum possible integer you can get if you split the array into k non-empty subsegments and take maximum of minimums on the subsegments.

Examples
input
5 2
1 2 3 4 5
output
5
input
5 1
-4 -5 -3 -2 -1
output
-5
Note

A subsegment [l,  r] (l ≤ r) of array a is the sequence al,  al + 1,  ...,  ar.

Splitting of array a of n elements into k subsegments [l1, r1], [l2, r2], ..., [lk, rk] (l1 = 1, rk = nli = ri - 1 + 1 for all i > 1) is k sequences (al1, ..., ar1), ..., (alk, ..., ark).

In the first example you should split the array into subsegments [1, 4] and [5, 5] that results in sequences (1, 2, 3, 4) and (5). The minimums are min(1, 2, 3, 4) = 1 and min(5) = 5. The resulting maximum is max(1, 5) = 5. It is obvious that you can't reach greater result.

In the second example the only option you have is to split the array into one subsegment [1, 5], that results in one sequence ( - 4,  - 5,  - 3,  - 2,  - 1). The only minimum is min( - 4,  - 5,  - 3,  - 2,  - 1) =  - 5. The resulting maximum is  - 5.

水题.

1. 当n=1的时候绝对是取这一串序列的最小值.

2. 当n=2是会分成两个区间,但不管怎么分是最左边与最右边的数一定是不同区间的,可以推一下,如果要取每个区间最小值中最大的,如序列3 4 1 3 2   / 代表分区间,会有四种分法:3 / 4 1 3 2    3 4 / 1 3 2   3 4 1 / 3 2    3 4 1 3 / 2  ,如果a[1]>a[0],那么最小的还是a[0], 没有变化,如果a[1]<a[0],区间最小值变小,无意义,,从后往前推也是这个道理,所以当n=2的情况下,只需要比较最左边与最右边就可以了.

3.当n=3时,可以直接取到最大的数。

#include<bits/stdc++.h>
using namespace std;
int main()
{
long long m,n,maxx=-,minn=,i,x,a[];
cin>>m>>n;
if(n==){
for(i=;i<m;i++){
cin>>x;
if(x<minn)
minn=x;
}
cout<<minn<<endl;
}
else if(n==){
for(i=;i<m;i++){
cin>>a[i];
}
cout<<max(a[],a[m-])<<endl;
}
else {
for(i=;i<m;i++){
cin>>x;
if(x>maxx)
maxx = x;
}
cout<<maxx<<endl;
}
return ;
}
C. Maximum splitting
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given several queries. In the i-th query you are given a single positive integer ni. You are to represent ni as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings.

An integer greater than 1 is composite, if it is not prime, i.e. if it has positive divisors not equal to 1 and the integer itself.

Input

The first line contains single integer q (1 ≤ q ≤ 105) — the number of queries.

q lines follow. The (i + 1)-th line contains single integer ni (1 ≤ ni ≤ 109) — the i-th query.

Output

For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings.

Examples
input
1
12
output
3
input
2
6
8
output
1
2
input
3
1
2
3
output
-1
-1
-1
Note

12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands.

8 = 4 + 4, 6 can't be split into several composite summands.

1, 2, 3 are less than any composite number, so they do not have valid splittings.

题目很简单,一开始没看懂题意,题意是求一个数n最多能分解成多少个非素数

优先考虑4,让其对4取模,这样就只有四种情况

余数为0时,正好整除必为多个4组成,这样就是最优解

余数为1时,4+4+1 = 9,退一位,n/4-1,余数1与两个 4凑成9,非素数

余数为2时,4+2=6,不变,4与余数2凑成6,非素数

余数为3时,4+4+4+3=6+9,退一位,(满足你>=15)

综上只要满足>=15,公式就可以通用

#include<bits/stdc++.h>
using namespace std; int main()
{
int n,m,ans,flag;
cin>>n;
while(n--)
{
scanf("%d",&m);
if(m==)printf("-1\n");
else
{
flag=m%;
if(flag==)ans=m/;
else if(flag==)ans=m/-;
else if(flag==)ans=m/;
else ans=m/-;
if(ans<=)
ans=-;
printf("%d\n",ans);
}
}
}

Codeforces Round #440 (Div. 2) A,B,C的更多相关文章

  1. Codeforces Round #440 (Div. 2)【A、B、C、E】

    Codeforces Round #440 (Div. 2) codeforces 870 A. Search for Pretty Integers(水题) 题意:给两个数组,求一个最小的数包含两个 ...

  2. Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2)

    A. Search for Pretty Integers 题目链接:http://codeforces.com/contest/872/problem/A 题目意思:题目很简单,找到一个数,组成这个 ...

  3. Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2) D. Something with XOR Queries

    地址:http://codeforces.com/contest/872/problem/D 题目: D. Something with XOR Queries time limit per test ...

  4. [日常] Codeforces Round #440 Div.2 大力翻车实况

    上次打了一发ABC然后大力翻车...上午考试又停电+Unrated令人非常滑稽...下午终于到了CF比赛... 赛前大力安利了一发然后拉了老白/ $ljm$ / $wcx$ 一起打, 然后搞了个 TI ...

  5. Codeforces Round #440 Div. 1

    A:显然应该尽量拆成4.如果是奇数,先拆一个9出来即可. #include<iostream> #include<cstdio> #include<cmath> # ...

  6. Codeforces Round #440 (Div. 1, based on Technocup 2018 Elimination Round 2) C - Points, Lines and Ready-made Titles

    C - Points, Lines and Ready-made Titles 把行列看成是图上的点, 一个点(x, y)就相当于x行 向 y列建立一条边, 我们能得出如果一个联通块是一棵树方案数是2 ...

  7. Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2) C. Maximum splitting

    地址: 题目: C. Maximum splitting time limit per test 2 seconds memory limit per test 256 megabytes input ...

  8. ACM-ICPC (10/15) Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2)

    A. Search for Pretty Integers You are given two lists of non-zero digits. Let's call an integer pret ...

  9. 【Codeforces Round #440 (Div. 2) C】 Maximum splitting

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 肯定用尽量多的4最好. 然后对4取模的结果 为0,1,2,3分类讨论即可 [代码] #include <bits/stdc++ ...

随机推荐

  1. 开源HTTP解析器---http-parser和fast-http

    由于项目中遇到需要发送http请求,然后再解析接收到的响应.大概在网上搜索了一下,有两个比较不错,分别是http-parser和fast-http. http-parser是由C编写的工具:fast- ...

  2. 多线程-synchronized、lock

    1.什么时候会出现线程安全问题? 在多线程编程中,可能出现多个线程同时访问同一个资源,可以是:变量.对象.文件.数据库表等.此时就存在一个问题: 每个线程执行过程是不可控的,可能导致最终结果与实际期望 ...

  3. 【LGR-048 五周年庆贺】洛谷6月月赛

    Luogu的五周年庆典比赛,还是比较满意的. 题目清新不毒瘤,数据优质不卡常,解法自然,为出题人点赞. 前三题的难度都很低,T5个人感觉还好.但是最后那个splay+hash是什么神仙东西. 最后好像 ...

  4. [Oracle]如何查看 10046 trace 中的 tim= ... 的具体时刻

    可以在  Linux 下,用下列方式: 如10046 trace 文件中如果有如下的内容:... tim = 1503032923 可以用 date 命令加 option 来看它的时刻: date - ...

  5. pycharm2019注册码一键实时获取,永久有效!

    pycharm2019专业版激活码 56ZS5PQ1RF-eyJsaWNlbnNlSWQiOiI1NlpTNVBRMVJGIiwibGljZW5zZWVOYW1lIjoi5q2j54mI5o6I5p2 ...

  6. 【JVM.8】类加载及执行子系统的案例与实战

    一. 案例分析 1. Tomcat:正统的类加载器架构 主流的Java Web服务器,如Tomcat.Jetty.WebLogic.WebSphere或其他服务器,都实现了自己定义的类加载器(一般都不 ...

  7. zabbix中配置当memory剩余不足20%时触发报警

    在zabbix中默认当内存剩余量不足2G的时候触发报警,并没有使用百分比来触发如下: 现在需要配置:当memory剩余不足20%时触发报警,具体操作方法如下: 1)创建itemConfiguratio ...

  8. Centos下内网DNS主从环境部署记录

    一.DNS是什么?DNS(Domain Name System),即域名系统.它使用层次结构的命名系统,将域名和IP地址相互映射,形成一个分布式数据库系统. DNS采用C-S架构,服务器端工作在UDP ...

  9. jenkins中配置svn 出现absolute path is not allowed

    代码: 兵马未动,粮草先行 作者: 传说中的汽水枪 如有错误,请留言指正,欢迎一起探讨. 转载请注明出处. 想用jenkins作自动化部署tomcat. svn代码已经checkout到本地目录了(/ ...

  10. Daily Scrumming* 2015.12.22(Day 14)

    一.团队scrum meeting照片 二.成员工作总结 姓名 任务ID 迁入记录 江昊 任务1112 无 任务说明 今天没有写前端界面,而是完成了跨域请求的实现以及用户实名认证API 前后端大部分数 ...