ACM-ICPC (10/15) Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2)
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?
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.
Print the smallest pretty integer.
2 3
4 2
5 7 6
25
8 8
1 2 3 4 5 6 7 8
8 7 6 5 4 3 2 1
1
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; int a[];
int b[]; int main()
{
int n,m;
scanf("%d%d",&n,&m); for(int i = ; i < n; i++) scanf("%d",&a[i]);
for(int i = ; i < m; i++) scanf("%d",&b[i]); sort(a,a+n);
sort(b,b+m); if(a[]==b[]) {
printf("%d\n",a[]);
}
else { bool flag = false;
int ans = ;
for(int i = ; i < n; i++) {
for(int j = ; j < m; j++) {
if(a[i]==b[j]) {
flag = true;
ans = a[i];
break;
}
}
if(flag)
break;
} if(flag)
printf("%d\n",ans);
else printf("%d%d\n",min(a[],b[]),max(a[],b[])); } return ;
}
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.
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).
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.
5 2
1 2 3 4 5
5
5 1
-4 -5 -3 -2 -1
-5
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 = n, li = 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 枚举
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5+; int a[maxn];
int d[maxn];
int d2[maxn]; int main() {
// freopen("in.txt","r",stdin);
int n,k;
scanf("%d%d",&n,&k); for(int i = ; i < n; i++)
d[i] = d2[i] = 1e9+; int maxx = -(1e9 + );
int minx = 1e9 + ;
for(int i = ; i < n; i++) {
scanf("%d",&a[i]);
minx = min(minx,a[i]);
maxx = max(maxx,a[i]);
} d[] = a[];
for(int i = ; i < n; i++) {
d[i] = min(d[i-],a[i]);
} d2[n-] = a[n-];
for(int i = n-; i >=; i--) {
d2[i] = min(d2[i+],a[i]);
} if(k==) {
printf("%d\n",minx);
} else if(k>)
printf("%d\n",maxx);
else {
if(a[]==maxx||a[n-]==maxx)
printf("%d\n",maxx);
else {
int ans = -(1e9+);
for(int i = ; i < n-; i++) {
int tmp = max(d[i],d2[i+]);
ans = max(ans,tmp);
}
printf("%d\n",ans);
}
} return ;
}
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.
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.
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.
1
12
3
2
6
8
1
2
3
1
2
3
-1
-1
-1
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去组合。
#include <bits/stdc++.h>
using namespace std;
int a[] = {,-,-,-,,-,,-,,,,-,,,,};
int main()
{
int q;
cin>>q;
while(q--) {
int n;
scanf("%d",&n);
if(n<=) {
printf("%d\n",a[n]);
continue;
}
int k = n%;
if(k==) printf("%d\n",n/);
if(k==) {
printf("%d\n",(n-)/+);
}
if(k==) {
printf("%d\n",(n-)/+);
}
if(k==) {
printf("%d\n",(n-)/+);
}
}
return ;
}

UVA 920

题目很形象,给定n个点坐标,从左往右的平行光线照射山峰,求图中红色的投影长度和。
分析:模拟照射过程,从右往左,只有下一个点较高的时候,才会有红色线段,而且此时的山峰不会再出现影子,维护一个尾部指针,指向当前可能产生影子的山峰,然后就是求影子长度了,投影长度和前一个点的角度有关,计算公式推导一下就行了。
#include <bits/stdc++.h>
using namespace std;
const int maxn = ;
struct Node {
double x,y;
bool operator < (const Node& rhs) const {
return x < rhs.x;
}
}nodes[maxn];
int n;
double dist(int i,int j) {
double x = nodes[i].x - nodes[j].x;
double y = nodes[i].y - nodes[j].y;
return sqrt(x*x+y*y);
}
int main()
{
//freopen("in.txt","r",stdin);
int t; scanf("%d",&t);
while(t--) {
scanf("%d",&n);
for(int i = ; i < n; i++) scanf("%lf%lf",&nodes[i].x,&nodes[i].y);
sort(nodes,nodes+n);
int last = n-;
double sum = ;
for(int i = n-; i >=; i--) {
if(nodes[i].y>nodes[last].y) {
sum += dist(i,i+)*( (nodes[i].y-nodes[last].y)/ (nodes[i].y-nodes[i+].y) );
last = i;
}
}
printf("%.2lf\n",sum);
}
return ;
}
ACM-ICPC (10/15) Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 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 题目意思:题目很简单,找到一个数,组成这个 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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的数量的最小值有关系,所以 ...
- 【模拟】 Codeforces Round #434 (Div. 1, based on Technocup 2018 Elimination Round 1) C. Tests Renumeration
题意:有一堆数据,某些是样例数据(假设X个),某些是大数据(假设Y个),但这些数据文件的命名非常混乱.要你给它们一个一个地重命名,保证任意时刻没有重名文件的前提之下,使得样例数据命名为1~X,大数据命 ...
- 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 ...
随机推荐
- Linux快捷指令
Linux创建一个快捷指令,直接跳转到某个目录中的某个文件 创建快捷指令命令: $ ln -s 源目录 目标快捷方式 删除快捷指令命令: $ unlink 快捷方式名 eg:比如我想在 /usr 目录 ...
- QiyeProject SpringMVC 项目 d15866p148.iok.la 主要做主页应用,消息应用不管了 用户微信号有点像乱码的那个是openID 找同伴:在项目的GitHub页面里找提问过的人,还有fork,star的人
消息型应用支持文本.图片.语音.视频.文件.图文等消息类型. 主页型应用只支持文本消息类型,且文本长度不超过20个字. 填写必要信息 URL /QiyeProject/src/org/oms/qiye ...
- web安全漏洞种类
(参考知道创宇) SQL注入: SQL注入(SQL Injection),是一个常见的发生于应用程序和数据库之间的web安全漏洞,由于在开发过程中的设计不当导致程序中忽略了检查,没有有效的过滤用户的输 ...
- shell 括号的区别
$() 用于命令交换 里面会会执行命令,如果你写其他的: 会直接报错的 ` ` 也是用于命令交换的哦 和$() 的操作是一样的 ${ } 用于变量替换 每次调用环境的时候是需要带一个${ } 但是 ...
- 深入理解JavaScript系列(30):设计模式之外观模式
介绍 外观模式(Facade)为子系统中的一组接口提供了一个一致的界面,此模块定义了一个高层接口,这个接口值得这一子系统更加容易使用. 正文 外观模式不仅简化类中的接口,而且对接口与调用者也进行了解耦 ...
- js之generate
generator(生成器)是ES6标准引入的新的数据类型.一个generator看上去像一个函数,但可以返回多次. ES6定义generator标准的哥们借鉴了Python的generator的概念 ...
- 【转】 ASP.NET使用ICallbackEventHandler无刷新验证用户名是否可用
功能说明:当用户在用户名输入框输入字符并焦点离开此输入框时,自动到数据库用户表中验证此用户名是否已被注册,如果已被注册,显示[不可用],反之,显示[可用],期间页面不刷新,读者也可以考虑将提示文字换成 ...
- 什么是SQL注入?什么是XSS攻击?什么是CSRF攻击?
1. XSS(Cross Site Script,跨站脚本攻击) 是向网页中注入恶意脚本在用户浏览网页时在用户浏览器中执行恶意脚本的攻击方式. 1.1跨站脚本攻击分有两种形式: 反射型攻击(诱使用户点 ...
- Python 基于固定 IP 来命名 ARM 虚拟机的实现
问题描述 希望通过 Python 批量创建 ARM 虚拟机,并且在虚拟机命名时加入固定 IP 信息,方便管理维护. 问题分析 在创建 ARM 虚拟机之前,先创建固定 IP,然后获取固定 IP 地址,创 ...
- SQL Server ->> 重命名数据库
ALTER DATABASE [oldDB] SET SINGLE_USER WITH ROLLBACK IMMEDIATE GO ALTER DATABASE [oldDB] MODIFY NAME ...