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是时间,可以利 ...
随机推荐
- Codeforces Round #389(div 2)
A =w= B QvQ C 题意:在一个格子图里给出一个路径 里面有UDLR四种移动方向 问 我在格子路径里面最少选几个点 可以让我沿着格子路径走 其实是在相邻的点与点之间走最短路 分析:贪心+模拟 ...
- Android系统匿名共享内存Ashmem(Anonymous Shared Memory)驱动程序源代码分析
文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/6664554 在上一文章Android系统匿名共 ...
- Android加载图片OOM错误解决方式
前几天做项目的时候,甲方要求是PAD (SAMSUNG P600 10.1寸 2560*1600)的PAD上显示高分辨率的大图片. SQLITE採用BOLD方式存储图片,这个存取过程就不说了哈,网上一 ...
- Flashback Query(函数示例)
Flashback Query 函数,存储过程,包,触发器等对象Flashback Drop 可以闪回与表相关联的对象, 如果是其他的对象,比如function,procedure,trigger等. ...
- Android的Fragment中onActivityResult不被调用的解决方案
常见的,我们会在FragmentActivity中嵌套一层Fragment使用,甚至两次或多层Fragment嵌套使用.这个时候,在第二级或者更深级别的Fragment调用startActivityF ...
- cocos2d-x创建工程批处理
cd /d D:\cocos2d-x-2.2.2\cocos2d-x-2.2.2\tools\project-creator create_project.py -project %1 -packag ...
- (原)安装windows8.1和ubuntu16双系统及相互访问磁盘
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5638232.html 参考网址: http://jingyan.baidu.com/article/f ...
- Java的String&StringBuffer&StringBuilder
一:String类 1.String对象的初始化 由于String对象特别用,所以在对String对象进行初始化时,Java提供了一种简化的特殊语法,格式如下: String s = "ab ...
- JavaScript match 和 exec 备忘笔记
这是一道广为引用的面试题:var someText="web2.0 .net2.0"; var pattern=/(\w+)(\d)\.(\d)/g; var outCome_ex ...
- Red and Black(poj 1979 bfs)
Red and Black Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 27891 Accepted: 15142 D ...