胖土逗 level
获赞
3
粉丝
0
关注
0
看过 TA
4
华中科技大学
2020
Java
IP属地:未知
暂未填写个人简介
私信
关注
2019-08-24 21:19
华中科技大学 Java
public class GouDong {     public static void main(String[] args){         System.out.println(Integer.MAX_VALUE);         new GouDong().exam1();     }     public void exam1(){         Scanner in = new Scanner(System.in);         while(in.hasNext()){             int n = in.nextInt();             int[...
胖十斤换网名的阿琛:#include <iostream> #include <vector> #include <map> #include <queue> #include <list> #include <algorithm> using namespace std; //首先定义一个结构体 Peo: 编号 + 熟人链表 + 权值p(熟人个数) typedef struct Peo { int id; list<int> fri; int p; }Peo; int main() { int n, m; while (cin >> n >> m) { int x, y; //存放让出去考试的学生编号,最后按从小到大打印 vector<int> result; vector<Peo> v(2 * n + 1); for (int i = 0; i < 2 * n + 1; ++i) v[i].id = i; //初始化v中所有学生的id v[0].p = -9999; //v[0]仅为占位方便计算,p定义成-9999不会影响排序 for (int i = 0; i < m; ++i) { cin >> x >> y; //接收好友关系 //x的好友列表 + y //y的好友列表 + x //各自权值+1 v[x].fri.push_back(y); v[y].fri.push_back(x); v[x].p++; v[y].p++; } sort(v.begin(), v.end(), [](const Peo&a, const Peo&b) { return a.p > b.p; }); //按权值从小到大排序 while (1) { if (v[0].p <= 0) break; //如果排序后v[0]<0则意味着所有的熟人关系均已处理掉 if (v[0].p > 0) { for (auto &f : v[0].fri) { for (auto &e : v) { if (e.id == f) { --e.p; break; } } } v[0].p = 0; result.push_back(v[0].id); } sort(v.begin(), v.end(), [](const Peo&a, const Peo&b) { return a.p > b.p; }); } cout << result.size() << endl; for (auto e : result) { cout << e << endl; } } return 0; }
投递京东等公司10个岗位 >
0 点赞 评论 收藏
分享

创作者周榜

更多
关注他的用户也关注了:
牛客网
牛客企业服务