比赛链接:牛客周赛47
赛时感受
又是一场思维题,应该只有EF有点算法,E需要使用快速幂和取余,F做不出,C卡了我一下,D写完了,E不写完一半又回来看C才做掉的,E也卡了很久虽然鸽巢原理想到了,但是没想到被卡在取余问题上,一开始没想出来,去做F然后做了半个小时发现做不掉,又回来在E上做功夫。
A
思路
代码
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 10;
ll n[N];
int main() {
int a, b, c, d, e;
cin >> n[1] >> n[2] >> n[3] >> n[4] >> n[5];
sort(n + 1, n + 1 + 5);
if ((n[3] == n[5] && n[1] == n[2]) || (n[1] == n[3] && n[4] == n[5])) cout << "YES" << endl;
else cout << "NO" << endl;
return 0;
}
B
思路
代码
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 10;
ll n;
int main() {
cin >> n;
string s[N];
for (int i = 1; i <= n; i++) {
cin >> s[i];
}
for (int i = 0; i < 26; i++) {
int flag = 0;
for (int j = 1; j <= n; j++) {
if (s[j].find('a' + i) == -1) {
flag = 1;
break;
}
}
if (flag)
continue;
cout << (char)('a' + i);
break;
}
return 0;
}
C
思路
代码
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 10;
ll n, a[N], sum, maxn;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum += a[i];
maxn = max(maxn, a[i]);
}
if (sum % 2 == 0) {
if (n == 2) {
if (a[1] == a[2]) {
cout << 0 << endl;
} else {
cout << 1 << endl;
}
} else if (sum <= maxn * 2 || (sum - maxn == n - 1)) {
cout << 1 << endl;
} else if (maxn == 1) {
cout << 0 << endl;
} else {
cout << n << endl;
}
} else {
if (sum <= maxn * 2 && maxn != 1) {
cout << 1 << endl;
} else {
cout << n << endl;
}
}
return 0;
}
D
思路
代码
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 10;
ll n, a[N] = { 1, 2, 4, 5, 7, 8, 10, 11, 14, 16, 17, 19, 20, 22, 25, 26, 28, 29 };
int main() {
int t;
cin >> t;
while (t--) {
ll n;
cin >> n;
cout << ((n - 1) / 18) * 30 + a[((n - 1) % 18)] << endl;
}
return 0;
}
E
思路
分类讨论横轴对称,纵轴对称和中心堆成,结果为横轴对称 + 纵轴堆成 - 中心对称
,因为中心堆成的部分都包含于横轴对称和纵轴堆成,若不减去则会计算两次。
纵轴对称的情况可能为:n为奇数时,纵轴所在的元素及其左边的元素只能选择
代码
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 10;
const ll mod = 1e9 + 7;
ll pow(ll x, ll y) {
ll res = 1;
while (y) {
if (y & 1) {
res *= x;
res %= mod;
}
y >>= 1;
x *= x;
x %= mod;
}
return res;
}
int main() {
ll n;
cin >> n;
if (n == 1) {
cout << 4 << endl;
return 0;
}
ll res = (((pow(4ll, n / 2) * (n % 2 == 1 ? 2ll : 1ll)) % mod + pow(4ll, n)) % mod - pow(2ll, ((n + 1) / 2)) + mod);
cout << (res % mod);
return 0;
}
F
思路
代码
标签:10,const,待补,47,ll,cin,long,牛客,int
From: https://www.cnblogs.com/againss/p/18251238