当前位置: 代码迷 >> 综合 >> CoderForces 479 div3 前五题
  详细解决方案

CoderForces 479 div3 前五题

热度:54   发布时间:2023-12-14 20:30:16.0

Wellcome to my csdn, Thank you !

This is CoderForces 479 div3.

  • Wellcome to my csdn, Thank you !
    • This is CoderForces 479 div3.
      • The first one “Wrong Subtraction”
      • The second one “Two-gram”
      • The third one “Less or Equal”
      • The fourth one “Divide by three, multiply by two”
      • The fifth one “Cyclic Components”

The first one “Wrong Subtraction”

#include<cstdio>
#include<iostream>
#include<cstring>
#include<math.h>
#include<map>
#include<algorithm>
#include<string>
#include<set>
#include<vector>
typedef long long LL;
const LL N = 200000 + 5;
#define INF 10000000
#define min(a , b) ((a) < (b) ? (a) : (b))
#define lowbit(x) x&-x
using namespace std;
typedef long long ll;
const int maxn = int(2e5) + 7;
ll  k[maxn], sum[maxn], dmg;
LL a[maxn], ans;
vector<int>v[N];int main() { //Test Oneint n, k;set<int>s;set<int>::iterator it;while (cin >> n >> k) {while (k--) {if (n == 0)break;if (n % 10)n--;else n /= 10;}cout << n << endl;}
}

The second one “Two-gram”

#include<cstdio>
#include<iostream>
#include<cstring>
#include<math.h>
#include<map>
#include<algorithm>
#include<string>
#include<set>
#include<vector>
typedef long long LL;
const LL N = 200000 + 5;
#define INF 10000000
#define min(a , b) ((a) < (b) ? (a) : (b))
#define lowbit(x) x&-x
using namespace std;
typedef long long ll;
const int maxn = int(2e5) + 7;
ll  k[maxn], sum[maxn], dmg;
LL a[maxn], ans;
vector<int>v[N];int main() {
   //Test Twoint n;cin >> n;char st[101];cin >> st;map<string, int>mp;map<int, string>ans;set<string>s;int a[101] = { 0 };int k = 0;int tt = 0;for (int i = 0; i < strlen(st) - 1; i++) {char t[3];t[0] = st[i];t[1] = st[i + 1];t[2] = '\0';s.insert(t);if (tt == s.size()) {a[mp[t]]++;}else{mp[t] = k;ans[k++] = t;a[mp[t]]++;tt = s.size();}}int max = 0;for (int i = 1; i < k; i++) {if (a[max] < a[i])max = i;}cout << ans[max] << endl;s.clear();
}

The third one “Less or Equal”

#include<cstdio>
#include<iostream>
#include<cstring>
#include<math.h>
#include<map>
#include<algorithm>
#include<string>
#include<set>
#include<vector>
typedef long long LL;
const LL N = 200000 + 5;
#define INF 10000000
#define min(a , b) ((a) < (b) ? (a) : (b))
#define lowbit(x) x&-x
using namespace std;
typedef long long ll;
const int maxn = int(2e5) + 7;
ll  k[maxn], sum[maxn], dmg;
LL a[maxn], ans;
vector<int>v[N];int main() {
   //Test Threeint n, k;while (cin >> n >> k) {for (int i = 0; i < n; i++) {scanf("%lld", &a[i]);}sort(a, a + n);if (k == 0) {if (a[0] == 1)cout << "-1\n";else cout << "1\n";continue;}//cout << a[k] << " " << a[k - 1] << endl;if (a[k] == a[k - 1])cout << "-1\n";else cout << a[k - 1] << endl;}
}

The fourth one “Divide by three, multiply by two”

#include<cstdio>
#include<iostream>
#include<cstring>
#include<math.h>
#include<map>
#include<algorithm>
#include<string>
#include<set>
#include<vector>
typedef long long LL;
const LL N = 200000 + 5;
#define INF 10000000
#define min(a , b) ((a) < (b) ? (a) : (b))
#define lowbit(x) x&-x
using namespace std;
typedef long long ll;
const int maxn = int(2e5) + 7;
ll  k[maxn], sum[maxn], dmg;
LL a[maxn], ans;
vector<int>v[N];int main() {
   //Test Fourint n;while (cin >> n) {int tt[101] = { 0 };LL next[101] = { 0 };for (int i = 1; i <= n; i++) {cin >> a[i];}for (int i = 1; i <= n; i++) {for (int j = 1; j <= n; j++) {if (i == j)continue;if (a[i] * 2 == a[j] || a[i] == a[j] * 3) {next[i] = j;tt[j] = 1;}}}for (int i = 1; i <= n; i++) {if (!tt[i]) {while (i) {cout << a[i] << " ";i = next[i];}return 0;}}cout << endl;}
}

The fifth one “Cyclic Components”

#include<cstdio>
#include<iostream>
#include<cstring>
#include<math.h>
#include<map>
#include<algorithm>
#include<string>
#include<set>
#include<vector>
typedef long long LL;
const LL N = 200000 + 5;
#define INF 10000000
#define min(a , b) ((a) < (b) ? (a) : (b))
#define lowbit(x) x&-x
using namespace std;
typedef long long ll;
const int maxn = int(2e5) + 7;
ll  k[maxn], sum[maxn], dmg;
LL a[maxn], ans;
vector<int>v[N];void dfs(int t) {a[t] = 1;if (v[t].size() != 2)ans = 0;for (int i = 0; i < v[t].size(); i++) {if (!a[v[t][i]])dfs(v[t][i]);}
}int main() {
   //Test fiveios::sync_with_stdio(false);int n, m;cin >> n >> m;memset(a, 0, sizeof(a));int s, e;for (int i = 0; i < m; i++) {cin >> s >> e;v[s].push_back(e);v[e].push_back(s);}int t = 0;for (int i = 0; i < n; i++) {if (!a[i]) {ans = 1;dfs(i);if (ans)t++;}}cout << t << endl;
}