codeforces #601 div2 ABC~E1

A. Changing Volume

Description

 

 

Solution

模拟水题.

 

B. Fridge Lockers

Description

 

 

 Solution

排序一遍,成环.然后剩下的从最小的里冲.

  1 #include <algorithm>
  2 #include <cctype>
  3 #include <cmath>
  4 #include <cstdio>
  5 #include <cstdlib>
  6 #include <cstring>
  7 #include <iostream>
  8 #include <map>
  9 #include <numeric>
 10 #include <queue>
 11 #include <set>
 12 #include <stack>
 13 #if __cplusplus >= 201103L
 14 #include <unordered_map>
 15 #include <unordered_set>
 16 #endif
 17 #include <vector>
 18 #define lson rt << 1, l, mid
 19 #define rson rt << 1 | 1, mid + 1, r
 20 #define LONG_LONG_MAX 9223372036854775807LL
 21 #define pblank putchar(' ')
 22 #define ll LL
 23 #define fastIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
 24 using namespace std;
 25 typedef long long ll;
 26 typedef long double ld;
 27 typedef unsigned long long ull;
 28 typedef pair<ll, int> P;
 29 int n, m, k;
 30 const int maxn = 1e5 + 10;
 31 template <class T>
 32 inline T read()
 33 {
 34     int f = 1;
 35     T ret = 0;
 36     char ch = getchar();
 37     while (!isdigit(ch))
 38     {
 39         if (ch == '-')
 40             f = -1;
 41         ch = getchar();
 42     }
 43     while (isdigit(ch))
 44     {
 45         ret = (ret << 1) + (ret << 3) + ch - '0';
 46         ch = getchar();
 47     }
 48     ret *= f;
 49     return ret;
 50 }
 51 template <class T>
 52 inline void write(T n)
 53 {
 54     if (n < 0)
 55     {
 56         putchar('-');
 57         n = -n;
 58     }
 59     if (n >= 10)
 60     {
 61         write(n / 10);
 62     }
 63     putchar(n % 10 + '0');
 64 }
 65 template <class T>
 66 inline void writeln(const T &n)
 67 {
 68     write(n);
 69     puts("");
 70 }
 71 template <typename T>
 72 void _write(const T &t)
 73 {
 74     write(t);
 75 }
 76 template <typename T, typename... Args>
 77 void _write(const T &t, Args... args)
 78 {
 79     write(t), pblank;
 80     _write(args...);
 81 }
 82 template <typename T, typename... Args>
 83 inline void write_line(const T &t, const Args &... data)
 84 {
 85     _write(t, data...);
 86     puts("");
 87 }
 88 int main(int argc, char const *argv[])
 89 {
 90 #ifndef ONLINE_JUDGE
 91     freopen("in.txt", "r", stdin);
 92     // freopen("out.txt", "w", stdout);
 93 #endif
 94     int t = read<int>();
 95     while (t--)
 96     {
 97         n = read<int>(), m = read<int>();
 98         vector<P> a(n);
 99         for (int i = 1; i <= n; i++)
100         {
101             int x = read<int>();
102             a[i - 1] = P(x, i);
103         }
104         sort(a.begin(), a.end());
105         if (m < n || n == 2)
106             puts("-1");
107         else
108         {
109             ll res = 0;
110             for (int i = 0; i < n; i++)
111                 res += a[i].first + a[(i + 1) % n].first;
112             for (int i = 0; i < m - n; i++)
113                 res += a[0].first + a[1].first;
114             writeln(res);
115             for (int i = 0; i < n; i++)
116                 write_line(a[i].second, a[(i + 1) % n].second);
117             for (int i = 0; i < m - n; i++)
118                 write_line(a[0].second, a[1].second);
119         }
120     }
121     return 0;
122 }
View Code

C. League of Leesins

Description

 Solution

出现一次的数肯定在开头或结尾,出现两次的数要么第二要么倒二.

然后确定俩数也就确定了第三个.

  1 #include <algorithm>
  2 #include <cctype>
  3 #include <cmath>
  4 #include <cstdio>
  5 #include <cstdlib>
  6 #include <cstring>
  7 #include <iostream>
  8 #include <map>
  9 #include <numeric>
 10 #include <queue>
 11 #include <set>
 12 #include <stack>
 13 #if __cplusplus >= 201103L
 14 #include <unordered_map>
 15 #include <unordered_set>
 16 #endif
 17 #include <vector>
 18 #define lson rt << 1, l, mid
 19 #define rson rt << 1 | 1, mid + 1, r
 20 #define LONG_LONG_MAX 9223372036854775807LL
 21 #define pblank putchar(' ')
 22 #define ll LL
 23 #define fastIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
 24 using namespace std;
 25 typedef long long ll;
 26 typedef long double ld;
 27 typedef unsigned long long ull;
 28 typedef pair<int, int> P;
 29 int n, m, k;
 30 const int maxn = 1e5 + 10;
 31 template <class T>
 32 inline T read()
 33 {
 34     int f = 1;
 35     T ret = 0;
 36     char ch = getchar();
 37     while (!isdigit(ch))
 38     {
 39         if (ch == '-')
 40             f = -1;
 41         ch = getchar();
 42     }
 43     while (isdigit(ch))
 44     {
 45         ret = (ret << 1) + (ret << 3) + ch - '0';
 46         ch = getchar();
 47     }
 48     ret *= f;
 49     return ret;
 50 }
 51 template <class T>
 52 inline void write(T n)
 53 {
 54     if (n < 0)
 55     {
 56         putchar('-');
 57         n = -n;
 58     }
 59     if (n >= 10)
 60     {
 61         write(n / 10);
 62     }
 63     putchar(n % 10 + '0');
 64 }
 65 template <class T>
 66 inline void writeln(const T &n)
 67 {
 68     write(n);
 69     puts("");
 70 }
 71 template <typename T>
 72 void _write(const T &t)
 73 {
 74     write(t);
 75 }
 76 template <typename T, typename... Args>
 77 void _write(const T &t, Args... args)
 78 {
 79     write(t), pblank;
 80     _write(args...);
 81 }
 82 template <typename T, typename... Args>
 83 inline void write_line(const T &t, const Args &... data)
 84 {
 85     _write(t, data...);
 86     puts("");
 87 }
 88 vector<int> g[maxn];
 89 unordered_map<int, int> mp;
 90 inline void add(int x, int y, int z)
 91 {
 92     g[x].emplace_back(y);
 93     g[x].emplace_back(z);
 94     g[y].emplace_back(x);
 95     g[y].emplace_back(z);
 96     g[z].emplace_back(x);
 97     g[z].emplace_back(y);
 98     mp[x]++;
 99     mp[y]++;
100     mp[z]++;
101 }
102 vector<int> res;
103 int vis[maxn];
104 void search(int f, int s)
105 {
106     res.clear();
107     res.emplace_back(f);
108     res.emplace_back(s);
109     vis[f] = vis[s] = 1;
110     int flag = 1;
111     for (int i = 1; i <= n - 2 && flag; i++)
112     {
113         int sz = g[f].size();
114         int q = 0;
115         for (int j = 0; j < sz; j++)
116         {
117             int v = g[f][j];
118             if (!vis[v])
119             {
120                 res.emplace_back(v);
121                 f = s;
122                 s = v;
123                 vis[v] = 1;
124                 break;
125             }
126         }
127     }
128 }
129 int main(int argc, char const *argv[])
130 {
131 #ifndef ONLINE_JUDGE
132     freopen("in.txt", "r", stdin);
133     // freopen("out.txt", "w", stdout);
134 #endif
135     n = read<int>();
136     for (int i = 0; i < n - 2; i++)
137     {
138         int q = read<int>(), w = read<int>(), e = read<int>();
139         add(q, w, e);
140     }
141     int f, s;
142     for (int i = 1; i <= n; i++)
143         if (mp[i] == 1)
144         {
145             f = i;
146             for (int j = 0; j < g[f].size(); j++)
147                 if (mp[g[f][j]] == 2)
148                     s = g[f][j];
149             break;
150         }
151     search(f, s);
152     for (int x : res)
153         write(x), pblank;
154     return 0;
155 }
View Code

 

E1. Send Boxes to Alice (Easy Version)

Description

Solution

晚点更新

posted @ 2019-11-28 17:11  mool  阅读(166)  评论(0编辑  收藏  举报