关于一道纽劢科技笔试题

第一行输入 t表示输出组数
比如
输入:
2(表示两组)
6(表示1 2 3 4 5 6)
2  (表示1 2)
输出
1 3 5 4 2 6
1 2
有什么好方法我运行超时了
#笔试题目#
全部评论
望指教,不懂为什么要用数组模拟?题目意思不是固定从1开始么,直接循环输出不就行了么
点赞 回复 分享
发布于 2019-04-05 13:41
没看懂要干嘛
1 回复 分享
发布于 2019-04-05 00:38
#include<iostream> #include<vector> using namespace std; int main() {     int T;     cin >> T;     int temp;     int count = 0;     vector<int> v;     while (T--) {         cin >> temp;         for (int i = 1; i <= temp; i++) {             v.push_back(i);         }         while (count < temp) {             for (int i = 0; i < v.size(); i += 2) {                 cout << v[i] << " ";                 count++;                 if (i + 1 < v.size()) {                     v.push_back(v[i + 1]);                 }             }         }         cout << endl;         v.clear();     } }
点赞 回复 分享
发布于 2019-05-09 21:10
#include <iostream> #include <queue>using namespace std; int T, n; void simulate(){ queue<int> q; for(int i=1; i<=n; i++) q.push(i); while(q.size()>1){ cout<<q.front()<<' '; q.pop(); q.push(q.front()); q.pop(); } cout<<q.front()<<endl;} int main(){ cin>>T; for(int t=0; t<T; t++){ cin>>n; simulate(); } return 0;}
点赞 回复 分享
发布于 2019-05-09 20:56
python 用queue做的AC了
点赞 回复 分享
发布于 2019-04-28 19:08
暴力递归了解下,但是我只有45% import java.util.Scanner; public class 纽劢1 {     public static void main(String[] args) throws Exception{         //输入         Scanner sc = new Scanner(System.in);         int t = Integer.parseInt(sc.nextLine());         int[] a = new int[t];         for (int i = 0; i < t; i++) {             a[i] = Integer.parseInt(sc.nextLine());         }         for (int k = 0; k < t; k++) {             int[] m = new int[a[k]];             for (int j = 1; j <= a[k]; j++) {                 m[j - 1] = j;             }             int last = last(m);             System.out.println(last);         }     }     //递归方法     public static int last(int[] m) {         //长度为2时输出,返回         if (m.length == 2) {             System.out.print(m[0] + " ");             return m[1];         }         //否则输出移除的数         System.out.print(m[0] + " ");         int[] s = new int[m.length - 1];         s[s.length - 1] = m[1];         for (int i = 2, j = 0; i <= s.length; i++, j++) {             s[j] = m[i];         }         return last(s);     } }
点赞 回复 分享
发布于 2019-04-14 15:40
C++直接用了数组,在数组里面直接从1到n插入数据,取数据放到新的数组,插入到最后就把当前数据插入到最后位置,然后i++,一直到i+1等于数组长度。
点赞 回复 分享
发布于 2019-04-06 04:22
队列模拟不是On嘛
点赞 回复 分享
发布于 2019-04-05 05:23
import java.util.Scanner; import java.util.ArrayList; public class Main{     public static void main(String[] args){         Scanner sc = new Scanner(System.in);         int len = sc.nextInt();         for(int i = 0; i < len; i++){             int nums = sc.nextInt();             getResult(nums);             System.out.println();         }     }          public static void getResult(int nums){         ArrayList<Integer> temp = new ArrayList<Integer>();         for(int i = 1; i <= nums; i++){             temp.add(i);         }         while(temp.size() >= 3){             System.out.print(temp.get(0) + " ");             temp.add(temp.get(1));             temp.remove(0);             temp.remove(0);         }         for(Integer i : temp){             System.out.print(i + " ");         }     } }
点赞 回复 分享
发布于 2019-04-05 01:45
queue模拟即可
点赞 回复 分享
发布于 2019-04-05 01:01
刚才做完就是简单模拟
点赞 回复 分享
发布于 2019-04-05 01:00
我用队列 没通过 哎
点赞 回复 分享
发布于 2019-04-05 00:43

相关推荐

面我面我面我_秋招版:不是戈门,干哪来了,这就是java嘛
点赞 评论 收藏
分享
真tmd的恶心,1.面试开始先说我讲简历讲得不好,要怎样讲怎样讲,先讲背景,再讲技术,然后再讲提升多少多少,一顿说教。2.接着讲项目,我先把背景讲完,开始讲重点,面试官立即打断说讲一下重点,无语。3.接着聊到了项目的对比学习的正样本采样,说我正样本采样是错的,我解释了十几分钟,还是说我错的,我在上一家实习用这个方法能work,并经过市场的检验,并且是顶会论文的复现,再怎么不对也不可能是错的。4.面试官,说都没说面试结束就退出会议,把面试者晾在会议里面,丝毫不尊重面试者难受的点:1.一开始是讲得不好是欣然接受的,毕竟是学习。2.我按照面试官的要求,先讲背景,再讲技术。当我讲完背景再讲技术的时候(甚至已经开始蹦出了几个技术名词),凭什么打断我说讲重点,是不能听出人家重点开始了?这也能理解,每个人都有犯错,我也没放心上。3.我自己做过的项目,我了解得肯定比他多,他这样贬低我做过的项目,说我的工作是错误的,作为一个技术人员,我是完全不能接受的,因此我就和他解释,但无论怎么解释都说我错。凭什么,作为面试官自己不了解相关技术,别人用这个方式work,凭什么还认为这个方法是错的,不接受面试者的解释。4.这个无可厚非,作为面试官,不打招呼就退出会议,把面试者晾着,本身就是有问题。综上所述,我现在不觉得第一第二点也是我的问题,面试官有很大的问题,就是专门恶心人的,总结面试官说教,不尊重面试者,打击面试者,不接受好的面试者,技术一般的守旧固执分子。有这种人部门有这种人怎么发展啊。最后去查了一下,岗位关闭了。也有可能是招到人了来恶心人的,但是也很cs
牛客20646354...:招黑奴啊,算法工程师一天200?
点赞 评论 收藏
分享
评论
点赞
2
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务