贴一份自己的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() ;  }
点赞 1

相关推荐

12-20 11:26
复旦大学 Java
点赞 评论 收藏
分享
嵌入式的小白:有道理哈,这种就看能不能捞
点赞 评论 收藏
分享
八极星:有什么不能问的,(/_\),这又不是多珍贵的机会,你有什么可失去的
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务