F - Investigating Imposters
假设A说B,如果B是“imposters",那么说明A也是“imposters”。
那么假设第i个人是“imposters",判断有多少个人也会是“imposters”。由于“imposters”人数有限制,多的不可能是。
#include <bits/stdc++.h>
// #define x first
// #define y second
typedef long long ll;
const int N = 511;
// #define PII pair<int, int>
const ll mod = (ll)1e9 + 7;
using namespace std;
vector<int> ve[N];
int vis[N];
int sz[N];
int dfs(int u) {
vis[u] = 1;
int v;
for (int i = 0; i < ve[u].size(); i++) {
v = ve[u][i];
if (!vis[v]) vis[u] += dfs(v);
}
return vis[u];
}
void solve() {
int n, m;
cin >> n >> m;
int f, g;
for (int i = 1; i <= n; i++) {
cin >> f;
for (int j = 0; j < f; j++) {
scanf("%d", &g);
if (g != i) ve[g].push_back(i);
}
}
for (int i = 1; i <= n; i++) {
memset(vis, 0, sizeof vis);
dfs(i);
sz[i] = vis[i];
}
memset(vis, 0, sizeof vis);
for (int i = 1; i <= n; i++) {
if (sz[i] <= m) {
vis[i] = 1;
}
}
for (int i = 1; i <= n; i++) {
if (vis[i])
printf("0\n");
else
printf("1\n");
}
}
int main() {
int t = 1;
// cin >> t;
while (t--) solve();
return 0;
}
dfs写成这样是因为我当时读错题了,又改成这样的。
G - Laptop Sticker
dddd
#include <bits/stdc++.h>
#define x first
#define y second
typedef long long ll;
const int N = 100100;
#define PII pair<int, int>
const ll mod = (ll)1e9 + 7;
using namespace std;
void solve() {
int a, b, c, d;
cin >> a >> b >> c >> d;
// cout << a - c << " " << b - d << "\n";
if (a - c > 1 && b - d > 1) {
cout << 1 << "\n";
} else {
cout << 0 << "\n";
}
}
int main() {
int t = 1;
// cin >> t;
while (t--) solve();
return 0;
}
longest Commom Substring
用find暴力就能过。
没必要用后缀自动机,那是大炮打蚊子
#include <bits/stdc++.h>
#define x first
#define y second
typedef long long ll;
const int N = 1100;
#define PII pair<int, int>
const ll mod = (ll)1e9 + 7;
using namespace std;
void solve() {
string s[N];
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s[i];
}
string t;
int flag;
int maxx = 0;
for (int i = 0; i < s[0].size(); i++) {
for (int j = 0; j < s[0].size(); j++) {
t = "";
flag = 0;
for (int k = i; k <= j; k++) {
t.push_back(s[0][k]);
}
for (int k = 1; k < n; k++) {
if (s[k].find(t) == s[k].npos) {
flag = 1;
break;
}
}
if (flag == 0) maxx = max(j - i + 1, maxx);
}
}
cout << maxx << "\n";
}
int main() {
int t = 1;
// cin >> t;
while (t--) solve();
return 0;
}
You Be The Judge!
强烈建议用cin,不要用getline
细节很多,具体看代码
如果非要用getline 不要忘了判\t
#include <bits/stdc++.h>
#define x first
#define y second
typedef long long ll;
const int N = 100100;
#define PII pair<int, int>
const ll mod = (ll)1e9 + 7;
using namespace std;
ll a[1010];
int judge(int n) {
if (n == 1) return 0;
int m = sqrt(n);
for (int i = 2; i <= m; i++) {
if (n % i == 0) return 0;
}
return 1;
}
int jnum(string s, int jj) {
a[jj] = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] < '0' || s[i] > '9') return 0;
if (a[jj] == 0 && s[i] == '0') return 0;
a[jj] *= 10ll;
a[jj] += (ll)s[i] - '0';
if (a[jj] > (ll)1e9) return 0;
}
if (a[jj] <= 0)
return 0;
else
return 1;
}
void solve() {
string s[1010];
int cnt = 0;
while (cin >> s[cnt]) {
cnt++;
}
if (cnt > 3) {
cout << 0 << "\n";
return;
}
if (jnum(s[0], 0) && jnum(s[1], 1) && jnum(s[2], 2)) {
// cout << a[0] << " " << a[1] << " " << a[2] << "\n";
if (judge(a[1]) && judge(a[2]) && a[0] == a[1] + a[2] && a[0] % 2 == 0) {
cout << 1 << "\n";
return;
}
}
cout << 0 << "\n";
}
int main() {
int t = 1;
// cin >> t;
while (t--) solve();
return 0;
}
I - Simple Cron Spec
大模拟
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
//#include <bits/stdc++.h>
#define x first
#define y second
typedef long long ll;
#define PII pair<int, int>
const ll mod = (ll)1e9 + 7;
using namespace std;
const int N = 1e3 + 10;
int n, k;
string s;
bool st[25][66][66];
vector<int> G[4];
void maa(int flag, int u) {
int sum = 0, l = -1, r = -1;
cin >> s;
if (s[0] == '*') {
if (flag == 0)
for (int i = 0; i <= 23; i++) G[u].push_back(i); // st[i] = true;
else
for (int i = 0; i <= 59; i++) G[u].push_back(i);
} else {
for (auto i : s) {
if (i == '-') {
l = sum;
sum = 0;
} else if (i == ',') {
if (l != -1) {
for (int j = l; j <= sum; j++) G[u].push_back(j);
} else
G[u].push_back(sum);
l = -1, r = -1;
sum = 0;
} else if (i == '*') {
for (int i = 0; i <= 23; i++) G[u].push_back(i);
} else
sum *= 10, sum += i - '0';
}
if (l != -1) {
for (int j = l; j <= sum; j++) G[u].push_back(j);
} else
G[u].push_back(sum);
}
}
void solve() {
cin >> n;
int ans = 0, cnt = 0;
for (int test = 1; test <= n; test++) {
for (int i = 0; i <= 2; i++) G[i].clear();
maa(0, 0);
maa(1, 1);
maa(1, 2);
for (int i = 0; i <= 2; i++) sort(G[i].begin(), G[i].end());
for (int i = 0; i <= 2; i++)
G[i].erase(unique(G[i].begin(), G[i].end()), G[i].end());
for (auto i : G[0]) {
for (auto j : G[1]) {
for (auto k : G[2]) {
// cout<<i<<' '<<j<<' '<<k<<endl;
if (st[i][j][k] == false) cnt++;
st[i][j][k] = true;
ans++;
}
}
}
}
cout << cnt << ' ' << ans << '\n';
}
int main() {
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}