Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <set>
- #include <string>
- #include <vector>
- #include <algorithm>
- using namespace std;
- #define ob push_back
- #define pii pair <int, int>
- bool is_dead = 0;
- pii ans = {-1, -1};
- vector <char> process(101, '.');
- map <char, int> resource;
- bool sh = 0;
- void look() {
- cout << "process depends on resource\n";
- for (int i = 0; i <= 100; ++i) {
- if (process[i] != '.') {
- cout << i << " " << process[i] << "\n";
- }
- }
- cout << "resource depends on process\n";
- for (auto p: resource) {
- if (p.second != -1) {
- cout << p.first << ' ' << p.second << "\n";
- }
- }
- cout << "\n";
- }
- bool dead(int x, int y) {
- if (process[x] == '.') {
- return 0;
- }
- if (process[y] == '.') {
- return 0;
- }
- char rex = process[x];
- char rey = process[y];
- return resource[rey] == x && resource[rex] == y;
- }
- void check() {
- for (int i = 0; i <= 100; ++i) {
- for (int j = 0; j <= 100; ++j) {
- if (i == j) {
- continue;
- }
- if (dead(i,j) && !is_dead) {
- is_dead = 1;
- ans = {i, j};
- }
- }
- }
- }
- int main()
- {
- for (int i = 0; i < 26; ++i) {
- char k = (int)'A' + i;
- process[k] = -1;
- }
- while (1) {
- if (sh) {
- look();
- }
- check();
- string restr;
- cin >> restr;
- int re;
- char pro, act;
- if (restr == ".") {
- break;
- }
- re = stoi(restr);
- cin >> pro >> act;
- if (act == 'U') {
- process[pro] = -1;
- for (int i = 0; i <= 100; ++i) {
- if (resource[i] == pro) {
- resource[i] = '.';
- }
- }
- continue;
- }
- if (process[pro] == -1) {
- process[pro] = re;
- continue;
- }
- resource[re] = pro;
- }
- if (is_dead) {
- cout << "DEADLOCK\n";
- cout << ans.first << " " << ans.second << "\n";
- exit(0);
- }
- cout << "NO DEADLOCK\n";
- int locked = 0;
- for (int i = 0; i <= 100; ++i) {
- if (resource[i] != '.') {
- locked++;
- }
- }
- cout << locked << "\n";
- }
Advertisement
Comments
-
- 101.166.94.231:27030 (Port can change)
- Please join in gmod i self-host servers. If i like you you can have one if not you have to make me an offer and i host it anyways, my provider is stupid!
-
- Name: Alex Hudson
- Discord:
- Radlic#2809
- Steam:
- https://steamcommunity.com/id/2528865
- Phones:
- (02) 6352 3590
- +61 263523590
- Home:
- 70 Calero St, Lithgow, NSW 2790, Australia.
- Add me, or write me a letter.. i'm so h0rny and need a cherry on my cake~
Add Comment
Please, Sign In to add comment
Advertisement