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是时间,可以利 ...
随机推荐
- LinQ to SQL 查询
LINQ to SQL 是将对象关系映射到.NET框架中的一种实现.它可以将关系数据库映射为.NET Framework中的一些类. 然后,开发人员就可以通过使用 LINQ to SQL对数据库中的数 ...
- ios 以NSObject为父类的各类间继承关系
- 修改UISearchBar背景色
//iOS7.1 [[[[_searchBar.subviews objectAtIndex:] subviews] objectAtIndex:] removeFromSuperview]; [_s ...
- 基础总结篇之二:Activity的四种launchMode
合抱之木,生於毫末:九層之台,起於累土:千里之行,始於足下.<老子> 今天在社区看到有朋友问“如何在半年内成为顶级架构师”,有网友道“关灯睡觉,不用半年的...”,的确,做梦还来的快一些. ...
- A10 平板开发二搭建Android开发环境
我是直接在Ubuntu 12.10 64位系统下操作的,搭建Ubuntu开发环境类似,见Ubuntu 10.04开发环境配置.需要注意的是,64位的系统,需要安装支持32位的库(sudo apt-ge ...
- 机房收费系统中的Grid++Report报表设计器的应用
在进行账单查询功能的时候我应用了Grid++Report报表设计器,下面我就为大家介绍一下,还望大家多多指点. 首先,在Grid++Report报表设计器中进行报表界面的设置.在属性编辑窗口中这里对报 ...
- iOS 8 Metal Swift教程(一) :开始学习
在本篇教程中,你将应用到3D图形中的一系列矩阵变换,并会学习到如下内容: 如何使用模型(model),视图(view)以及投影变换(projection transformations). 如何使用矩 ...
- SOLR使用手册之操作collection
一.Collections API 参考:https://cwiki.apache.org/confluence/display/solr/Collections+API 因为API比较多,我就不一 ...
- asp.net 通过js调用webService注意
通过JavaSrcipt调用WebService格式: //通过SricptManager 的,services标签添加web服务引用 <asp:ScriptManager runat=&quo ...
- javaScript事件机制兼容【整理】
[添加事件机制] addEventListener 和 attachEvent [W3C] addEventListener('click' , function(){alert('Hello ...