Co-prime Array&&Seating On Bus(两道水题)
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
You are given an array of n elements, you must make it a co-prime array in as few moves as possible.
In each move you can insert any positive integral number you want not greater than 109 in any place in the array.
An array is co-prime if any two adjacent numbers of it are co-prime.
In the number theory, two integers a and b are said to be co-prime if the only positive integer that divides both of them is 1.
Input
The first line contains integer n (1 ≤ n ≤ 1000) — the number of elements in the given array.
The second line contains n integers ai (1 ≤ ai ≤ 109) — the elements of the array a.
Output
Print integer k on the first line — the least number of elements needed to add to the array a to make it co-prime.
The second line should contain n + k integers aj — the elements of the array a after adding k elements to it. Note that the new array should be co-prime, so any two adjacent values should be co-prime. Also the new array should be got from the original array a by addingk elements to it.
If there are multiple answers you can print any one of them.
Sample Input
3 2 7 28
1 2 7 9 28
题意:让加最少的数使成为互质集合:相邻两个数互质;。。。水,1与任何数互质
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int INF = 0x3f3f3f3f;
#define mem(x,y) memset(x,y,sizeof(x))
const int MAXN = ;
int num[MAXN];
int ans[MAXN << ];
int gcd(int a,int b){
return b == ? a : gcd(b, a%b);
}
/*
int find(int a, int b){
for(int i )
}
*/
int main(){
int N;
while(~scanf("%d", &N)){
int tp = ;
for(int i = ; i <= N; i++){
scanf("%d", num + i);
}
ans[tp++] = num[];
for(int i = ; i <= N; i++){
if(gcd(num[i], num[i - ]) != ){
ans[tp++] = ;
ans[tp++] = num[i];
}
else ans[tp++] = num[i];
}
printf("%d\n", tp - N);
for(int i = ; i < tp; i++){
if(i)printf(" ");
printf("%d", ans[i]);
}
puts("");
}
return ;
}
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
Consider 2n rows of the seats in a bus. n rows of the seats on the left and n rows of the seats on the right. Each row can be filled by two people. So the total capacity of the bus is 4n.
Consider that m (m ≤ 4n) people occupy the seats in the bus. The passengers entering the bus are numbered from 1 to m (in the order of their entering the bus). The pattern of the seat occupation is as below:
1-st row left window seat, 1-st row right window seat, 2-nd row left window seat, 2-nd row right window seat, ... , n-th row left window seat, n-th row right window seat.
After occupying all the window seats (for m > 2n) the non-window seats are occupied:
1-st row left non-window seat, 1-st row right non-window seat, ... , n-th row left non-window seat, n-th row right non-window seat.
All the passengers go to a single final destination. In the final destination, the passengers get off in the given order.
1-st row left non-window seat, 1-st row left window seat, 1-st row right non-window seat, 1-st row right window seat, ... , n-th row left non-window seat, n-th row left window seat, n-th row right non-window seat, n-th row right window seat.
The seating for n = 9 and m = 36.
You are given the values n and m. Output m numbers from 1 to m, the order in which the passengers will get off the bus.
Input
The only line contains two integers, n and m (1 ≤ n ≤ 100, 1 ≤ m ≤ 4n) — the number of pairs of rows and the number of passengers.
Output
Print m distinct integers from 1 to m — the order in which the passengers will get off the bus.
Sample Input
2 7
5 1 6 2 7 3 4
9 36
19 1 20 2 21 3 22 4 23 5 24 6 25 7 26 8 27 9 28 10 29 11 30 12 31 13 32 14 33 15 34 16 35 17 36 18
题意:坐公交车。。。水;
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int INF = 0x3f3f3f3f;
#define mem(x,y) memset(x,y,sizeof(x))
const int MAXN = ;
int num[][MAXN];
int main(){
int n,m;
while(~scanf("%d%d",&n, &m)){
int tp = ;
for(int i = ; i <= n; i++){
num[][i] = ++tp;
num[][i] = ++tp;
}
for(int i = ; i <= n; i++){
num[][i] = ++tp;
num[][i] = ++tp;
}
int x = ;
for(int i = ; i <= n; i++){
if(num[][i] <= m){
if(x)printf(" ");
printf("%d",num[][i]);
x++;
}
if(num[][i] <= m){
if(x)printf(" ");
printf("%d",num[][i]);
x++;
}
if(num[][i] <= m){
if(x)printf(" ");
printf("%d",num[][i]);
x++;
}
if(num[][i] <= m){
if(x)printf(" ");
printf("%d",num[][i]);
x++;
} }
puts("");
}
return ;
}
Co-prime Array&&Seating On Bus(两道水题)的更多相关文章
- 【转】POJ百道水题列表
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
- 『ACM C++』Virtual Judge | 两道基础题 - The Architect Omar && Malek and Summer Semester
这几天一直在宿舍跑PY模型,学校的ACM寒假集训我也没去成,来学校的时候已经18号了,突然加进去也就上一天然后排位赛了,没学什么就去打怕是要被虐成渣,今天开学前一天,看到最后有一场大的排位赛,就上去试 ...
- 1503171912-ny-一道水题
一道水题 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描写叙述 今天LZQ在玩一种小游戏,可是这游戏数有一点点的大,他一个人玩的累.想多拉一些人进来帮帮他.你能写一个程序帮 ...
- Java基础知识强化11:多态的两道基础题
1.第1题 class Base { public void method() { System.out.print("Base method"); } } class Child ...
- 逛园子,看到个练习题,小试了一把(淘宝ued的两道小题)
闲来无事,逛园子,充充电.发现了一个挺有意思的博文,自己玩了一把. 第一题:使用 HTML+CSS 实现如图布局,border-widht 1px,一个格子大小是 60*60,hover时候边框变为橘 ...
- MT【327】两道不等式题
当$x,y\ge0,x+y=2$时求下面式子的最小值:1)$x+\sqrt{x^2-2x+y^2+1}$2)$\dfrac{1}{5}x+\sqrt{x^2-2x+y^2+1}$ 解:1)$P(x,y ...
- MT【235】两道函数题
已知$g(x)=x^2-ax+4a$,记$h(x)=|\dfrac{x}{g(x)}|$,若$h(x)$在$(0,1]$上单调递增,求$a$的取值范围. 解答: 已知$$g(x)=\begin{cas ...
- [转载]2014年10月26完美世界校招两道java题
public class VolitileTest { volatile static int count=0; public static void main(String args[]){ for ...
- DASCTF七月赛两道Web题复现
Ezfileinclude(目录穿越) 拿到http://183.129.189.60:10012/image.php?t=1596121010&f=Z3F5LmpwZw== t是时间,可以利 ...
随机推荐
- 《招聘一个靠谱的iOS》面试题参考答案(上)
说明:面试题来源是微博@我就叫Sunny怎么了的这篇博文:<招聘一个靠谱的 iOS>,其中共55题,除第一题为纠错题外,其他54道均为简答题. 博文中给出了高质量的面试题,但是未给出答案, ...
- java二维码开发
之前就写过很多关于二维码的东西,一直没有时间整理一下,所以呢今天就先来介绍一下如何利用java开发二维码.生成二维码有很多jar包可以实现,例如Zxing,QRcode,前者是谷歌的,后者日本的,这里 ...
- Hibernate PO对象的状态
Hibernate的PO对象有三种状态:临时状态(又称临时态).持久状态(又称为持久态)和脱管状态(又称为脱管态.游离态).处理持久态的对象也称为PO,临时对象和脱管对象也称为VO. 1.临时态: 简 ...
- SQL内连接-外连接join,left join,right join,full join
1.创建测试表test1及test2 SQL)); 表已创建. SQL)); 表已创建. ,'name1'); ,'name2'); ,'name3'); ,'name4'); ,'name5'); ...
- js 分割循环
var str ='1,2,3'; var arr = str.split(","); var array1 =[]; var array2 =[]; for(i=0,l=arr. ...
- Android-----输入法的显示和隐藏
/** * 控制手机虚拟键盘的显示和隐藏 */public class InputMethodUtil { /** * 隐藏虚拟键盘 * @param v 参数v为获取焦点对象view */ pub ...
- js渲染的3d玫瑰
参看下面链接: 程序员最美情人节礼物:JS渲染的3D玫瑰
- [C++程序设计]指针总结
- [C++程序设计]函数的递归调用
在调用一个函数的过程中又出现直接或间接地调用 该函数本身,称为函数的递归(recursive)调用. 包含递归调用的函数称为递归函数. 在实现递归时,在时间和空间上的开销比较大 求n! #includ ...
- wordpress教程之WP_Query()类
WP_Query的使用方法 在讲WP_Query之前我们要先区分一下两个名词: WP_Query是WordPress自带的的一个用于处理复杂请求的类(这里的请求的内容不仅包括文章,还可能是页面,用户, ...