A. Search for Pretty Integers

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
  1. 2 3
    4 2
    5 7 6
output
  1. 25
input
  1. 8 8
    1 2 3 4 5 6 7 8
    8 7 6 5 4 3 2 1
output
  1. 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.

题意:找出两个数字,在两个数组都出现过,要求最小,注意,有可能只有一位。

  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int a[];
  6. int b[];
  7.  
  8. int main()
  9. {
  10. int n,m;
  11. scanf("%d%d",&n,&m);
  12.  
  13. for(int i = ; i < n; i++) scanf("%d",&a[i]);
  14. for(int i = ; i < m; i++) scanf("%d",&b[i]);
  15.  
  16. sort(a,a+n);
  17. sort(b,b+m);
  18.  
  19. if(a[]==b[]) {
  20. printf("%d\n",a[]);
  21. }
  22. else {
  23.  
  24. bool flag = false;
  25. int ans = ;
  26. for(int i = ; i < n; i++) {
  27. for(int j = ; j < m; j++) {
  28. if(a[i]==b[j]) {
  29. flag = true;
  30. ans = a[i];
  31. break;
  32. }
  33. }
  34. if(flag)
  35. break;
  36. }
  37.  
  38. if(flag)
  39. printf("%d\n",ans);
  40. else printf("%d%d\n",min(a[],b[]),max(a[],b[]));
  41.  
  42. }
  43.  
  44. return ;
  45. }
B. Maximum of Maximums of Minimums

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
  1. 5 2
    1 2 3 4 5
output
  1. 5
input
  1. 5 1
    -4 -5 -3 -2 -1
output
  1. -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.

题意:给定一个数组,划分为k个区间,最大化,区间内最小的数字的最大值。有点绕。

k > 2 ans = maxx

k = 1 ans = minx

k==2 枚举

  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int maxn = 1e5+;
  6.  
  7. int a[maxn];
  8. int d[maxn];
  9. int d2[maxn];
  10.  
  11. int main() {
  12. // freopen("in.txt","r",stdin);
  13. int n,k;
  14. scanf("%d%d",&n,&k);
  15.  
  16. for(int i = ; i < n; i++)
  17. d[i] = d2[i] = 1e9+;
  18.  
  19. int maxx = -(1e9 + );
  20. int minx = 1e9 + ;
  21. for(int i = ; i < n; i++) {
  22. scanf("%d",&a[i]);
  23. minx = min(minx,a[i]);
  24. maxx = max(maxx,a[i]);
  25. }
  26.  
  27. d[] = a[];
  28. for(int i = ; i < n; i++) {
  29. d[i] = min(d[i-],a[i]);
  30. }
  31.  
  32. d2[n-] = a[n-];
  33. for(int i = n-; i >=; i--) {
  34. d2[i] = min(d2[i+],a[i]);
  35. }
  36.  
  37. if(k==) {
  38. printf("%d\n",minx);
  39. } else if(k>)
  40. printf("%d\n",maxx);
  41. else {
  42. if(a[]==maxx||a[n-]==maxx)
  43. printf("%d\n",maxx);
  44. else {
  45. int ans = -(1e9+);
  46. for(int i = ; i < n-; i++) {
  47. int tmp = max(d[i],d2[i+]);
  48. ans = max(ans,tmp);
  49. }
  50. printf("%d\n",ans);
  51. }
  52. }
  53.  
  54. return ;
  55. }
C. Maximum splitting

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. 1
    12
output
  1. 3
input
  1. 2
    6
    8
output
  1. 1
    2
input
  1. 3
    1
    2
    3
output
  1. -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去组合。

  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int a[] = {,-,-,-,,-,,-,,,,-,,,,};
  6.  
  7. int main()
  8. {
  9. int q;
  10. cin>>q;
  11. while(q--) {
  12. int n;
  13. scanf("%d",&n);
  14. if(n<=) {
  15. printf("%d\n",a[n]);
  16. continue;
  17. }
  18. int k = n%;
  19. if(k==) printf("%d\n",n/);
  20. if(k==) {
  21. printf("%d\n",(n-)/+);
  22. }
  23. if(k==) {
  24. printf("%d\n",(n-)/+);
  25. }
  26. if(k==) {
  27. printf("%d\n",(n-)/+);
  28. }
  29. }
  30. return ;
  31. }

UVA 920

题目很形象,给定n个点坐标,从左往右的平行光线照射山峰,求图中红色的投影长度和。

分析:模拟照射过程,从右往左,只有下一个点较高的时候,才会有红色线段,而且此时的山峰不会再出现影子,维护一个尾部指针,指向当前可能产生影子的山峰,然后就是求影子长度了,投影长度和前一个点的角度有关,计算公式推导一下就行了。

  1. #include <bits/stdc++.h>

  2. using namespace std;

  3. const int maxn = ;

  4. struct Node {
  5. double x,y;
  6. bool operator < (const Node& rhs) const {
  7. return x < rhs.x;
  8. }
  9. }nodes[maxn];

  10. int n;

  11. double dist(int i,int j) {
  12. double x = nodes[i].x - nodes[j].x;
  13. double y = nodes[i].y - nodes[j].y;
  14. return sqrt(x*x+y*y);
  15. }

  16. int main()
  17. {
  18. //freopen("in.txt","r",stdin);
  19. int t; scanf("%d",&t);
  20. while(t--) {
  21. scanf("%d",&n);

  22. for(int i = ; i < n; i++) scanf("%lf%lf",&nodes[i].x,&nodes[i].y);
  23. sort(nodes,nodes+n);

  24. int last = n-;

  25. double sum = ;
  26. for(int i = n-; i >=; i--) {
  27. if(nodes[i].y>nodes[last].y) {
  28. sum += dist(i,i+)*( (nodes[i].y-nodes[last].y)/ (nodes[i].y-nodes[i+].y) );
  29. last = i;
  30. }
  31. }

  32. printf("%.2lf\n",sum);

  33. }

  34. return ;
  35. }

ACM-ICPC (10/15) Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2)的更多相关文章

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

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

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

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

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

  5. Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1)&&Codeforces 861B Which floor?【枚举,暴力】

    B. Which floor? time limit per test:1 second memory limit per test:256 megabytes input:standard inpu ...

  6. Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1)&&Codeforces 861A k-rounding【暴力】

    A. k-rounding time limit per test:1 second memory limit per test:256 megabytes input:standard input ...

  7. Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1)

    A. k-rounding 题目意思:给两个数n和m,现在让你输出一个数ans,ans是n倍数且末尾要有m个0; 题目思路:我们知道一个数末尾0的个数和其质因数中2的数量和5的数量的最小值有关系,所以 ...

  8. 【模拟】 Codeforces Round #434 (Div. 1, based on Technocup 2018 Elimination Round 1) C. Tests Renumeration

    题意:有一堆数据,某些是样例数据(假设X个),某些是大数据(假设Y个),但这些数据文件的命名非常混乱.要你给它们一个一个地重命名,保证任意时刻没有重名文件的前提之下,使得样例数据命名为1~X,大数据命 ...

  9. Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1)&&Codeforces 861C Did you mean...【字符串枚举,暴力】

    C. Did you mean... time limit per test:1 second memory limit per test:256 megabytes input:standard i ...

随机推荐

  1. 获取window.location.href路径参数

    GetQueryString(param) { //param为要获取的参数名 注:获取不到是为null var currentUrl = window.location.href; //获取当前链接 ...

  2. Epplus导出Excel(DataTable)

    1.先将dataTable转换成流 public Stream DataTableToExcel(DataTable dataTable, string[] columns, string sheet ...

  3. oracle 笔记---(六)__表空间

    查看表空间的大小 select tablespace_name,block_size,contents from dba_tablespaces; 查看表空间对应的数据文件 select file_n ...

  4. Oracle RAC集群删除节点

    一,节点环境 [root@node1 ~]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost ...

  5. mysql DCl语句

    DCl 语句主要书DBA用来管理系统中的对象权限使用 grant select,insert on sakila.* 'kingle'@'localhost' identified by '123'; ...

  6. 15019:Only the instance admin may alter the PermSize attribute

    15019:Only the instance admin may alter the PermSize attribute TimesTen提示空间不足,增加空间重启后提示15019:Only th ...

  7. 生产者与消费者模式-阻塞 wait,notify

    设计思路:生产者push ,消费者 拿,篮子装,syncstack先进后出,while 判断 index=0 wait,      当 Producer生产了 并push到篮子里  notify(唤醒 ...

  8. go test遇到的一些问题-command-line-arguments undefined: xxxxx

    一 问题是在我写算法题的时候出的,test后缀的文件编译报command-line-arguments undefined: xxxxx 二 没记错,go test是 所有在以_test结尾的源码内以 ...

  9. c#中日期的处理

    DateTime.Now.ToShortDateString()//只取日期DateTime.Now.ToLongTimeString();//只取时间搞定DateTime.Now.ToShortTi ...

  10. Cookie的创建、读取、删除

    创建Cookie: HttpCookie cookie =  new HttpCookie(COOKIE_NAME_FOR_USER);cookie.Expires = DateTime.Now.Ad ...