2018.8.18 贝壳找房取消社团预约 题解

2018.8.18 贝壳找房取消社团预约

我看圈子里没有人发这个的解答

献个丑把自己的贴出来    (用的python)

有需要改进的地方欢迎大家提出来





#笔试题目##贝壳找房##题解#
全部评论
Java版本的+1: https://paste.ubuntu.com/p/yZ8Kn8q3NY/
点赞 回复 分享
发布于 2018-08-19 16:23
贴下一个java版本的。 package beike; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Scanner; public class Main2 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); ArrayList<Time> list = new ArrayList<>(); for(int i=0;i<n;i++){ int start = sc.nextInt(); int end = sc.nextInt(); list.add(new Time(i+1,start, end)); } Collections.sort(list); ArrayList<Integer> res = new ArrayList<>(); loop1: for(int i=0;i<n;i++){ for(int j=0;i<n;j++){ if(j==i) continue; int pre = j; int next = j+1; if(next == i){ next = i+1; } if(next == n){ break; } if(list.get(pre).end > list.get(next).start){ continue loop1; } } res.add(list.get(i).id); } Collections.sort(res); System.out.println(res.size()); for(int i=0;i<res.size();i++){ System.out.print(res.get(i)); if(i!=res.size()-1){ System.out.print(" "); } } System.out.println(); } } class Time implements Comparable<Time>{ public int id; public int start; public int end; public Time(int i,int s,int e){ this.id = i; this.start = s; this.end = e; } @Override public int compareTo(Time o) { return this.start - o.start; } }
点赞 回复 分享
发布于 2018-08-19 16:22
求一份c++的
点赞 回复 分享
发布于 2018-08-19 16:24
做出前两题的都是大神啊
点赞 回复 分享
发布于 2018-08-19 16:38
说实话我没看懂那个题。。。
点赞 回复 分享
发布于 2018-08-20 00:35
贴一份自己的C++: #include <iostream> #include <string> #include <algorithm> #include <map> #include <vector> using namespace std; class use { public:     use(int start, int end,int index) { this->start = start; this->end = end; this->index = index;}     int start;     int end;     int index; }; bool compare(use &u1, use &u2) {     return u1.start < u2.start; } void solution() {     int n;     cin >> n;     vector<use> shetuan;     for (int i = 0; i < n; ++i)     {         int temp1, temp2;         cin >> temp1 >> temp2;         shetuan.emplace_back(use(temp1, temp2,i+1));     }     sort(shetuan.begin(), shetuan.end(), compare);     bool isFirst = true;     bool isCan = true;     vector<int> res;     int minTime, maxTime;     for (int i = 0; i < n; ++i)     {         for (int j = 0; j < n; ++j)         {             if (i != j)             {                 if (isFirst)                 {                     minTime = shetuan[j].start;                     maxTime = shetuan[j].end;                     isFirst = false;                 }                 else                 {                     if (shetuan[j].start < maxTime)                     {                         isCan = false;                         break;                     }                     maxTime = shetuan[j].end;                 }             }         }         if (isCan)             res.emplace_back(shetuan[i].index);         isFirst = true;         isCan = true;     }     if (res.size() == 0)         cout << 0;     else     {         cout << res.size()<<endl;         sort(res.begin(), res.end());         for (int i = 0; i < res.size(); ++i)         {             cout << res[i];             if (i != res.size() - 1)                 cout << " ";         }     } } int main() {    solution() ;  }
点赞 回复 分享
发布于 2018-08-20 15:49

相关推荐

云边有个小卖铺儿:校招生违约率低,所以我要高😂
点赞 评论 收藏
分享
你见过凌晨四点的牛客吗_BY_KobeBryant:明年再投都一样😂😂
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务