A 签到题
#include <iostream>
#include <cstring>
using namespace std;
void solve() {
int a, b, c;
cin >> a >> b >> c;
if(a == b) cout << c << endl;
else if(a == c) cout << b << endl;
else if(b == c) cout << a << endl;
}
int main() {
int t;
cin >> t;
while(t -- ) {
solve();
}
return 0;
}
B 签到题
#include <iostream>
using namespace std;
const int N = 5;
char g[N][N];
void solve() {
int posx = 0;
int posy = 0;
for(int i = 1; i <= 3; i ++ ) {
for(int j = 1; j <= 3; j ++ ) {
cin >> g[i][j];
if(g[i][j] == '?')
posx = i, posy = j;
}
}
bool flagA = false, flagB = false, flagC = false;
for(int i = 1; i <= 3; i ++ ) {
if(g[posx][i] == 'A') flagA = true;
if(g[posx][i] == 'B') flagB = true;
if(g[posx][i] == 'C') flagC = true;
}
if(!flagA) cout << "A" << endl;
if(!flagB) cout << "B" << endl;
if(!flagC) cout << "C" << endl;
}
int main() {
int t;
cin >> t;
while(t -- ) {
solve();
}
return 0;
}
C Can I square?
题目
思路:设wooden squares的数量为n 如果 n / (int)sqrt(n) == sqrt(n)则满足题意
#include <iostream>
#include <cmath>
using namespace std;
const int N = 2e5 + 10;
const double eps = 1e-18;
int a[N];
int n;
void solve() {
cin >> n;
long long cnt = 0;
for(int i = 1; i <= n; i ++ ) {
cin >> a[i];
cnt += a[i];
}
if(sqrt(cnt) == cnt / (int)sqrt(cnt)) cout << "YES" << endl;
else cout << "NO" << endl;
}
int main() {
int t;
cin >> t;
while(t -- ) {
solve();
}
return 0;
}
D Unnatural Language Processing
‘.’由于题目所给字符串合法,因此CVC后一定是C 先找出所有的类似CVCC的结构并在第二个C上做标记这个标记表示辅元辅音节,第二次遍历时如果碰见V如果这个V后面的C没有被标记则说明这里的V是辅元结构应该标记
注意字符串末尾不需要标记要特判
代码:
#include <iostream>
#include <cstring>
using namespace std;
const int N = 2e5 + 10;
bool st[N];
char str[N];
int n;
bool isV(char c) {
return c == 'a' || c == 'e';
}
void solve() {
memset(st, 0, sizeof st);
cin >> n;
for(int i = 1; i <= n; i ++ ) cin >> str[i];
str[n + 1] = 'w';
for(int i = 1; i <= n - 1; i ++ ) {
if(isV(str[i])) {//这里是元音
if(!isV(str[i + 1]) && !isV(str[i + 2])) {
st[i + 1] = true;
}
}
}
for(int i = 1; i <= n - 1; i ++ ) if(isV(str[i]) && !st[i + 1]) st[i] = true;
for(int i = 1; i <= n; i ++ ) {
cout << str[i];
if(i < n)
if(st[i]) cout << ".";
}
cout << endl;
}
int main() {
int t;
cin >> t;
while(t -- ) {
solve();
}
return 0;
}
E romantic glasses
题目:
思路 前缀和 + 推公式
如果存在 s奇1 - s奇2 = s偶1 - s偶2 == s奇1 - s偶1 = s奇2 - s偶2 则满足题意 可以用map存所有的s奇 - s偶 时间复杂度O(n * log2n)
问题:
输入和解决在一个循环中,如果判对会跳出循环,若本轮数据未输入完,则会影响下一轮数据的输入
代码
#include <iostream>
#include <map>
#include <cstring>
using namespace std;
const int N = 2e5 + 10;
long long sum[2];
int n;
void solve() {
memset(sum, 0, sizeof sum);
map<long long, int> ma;
cin >> n;
ma[0] ++;
bool flag = false;
for(int i = 1; i <= n; i ++ ) {
int x;
cin >> x;
sum[i & 1] += x;
if(ma[sum[1] - sum[0]] && !flag) {
cout << "YES" << endl;
flag = true;
}
ma[sum[1] - sum[0]] ++;
}
if(!flag)
cout << "NO" << endl;
}
int main() {
int t;
cin >> t;
while(t -- ) {
solve();
}
return 0;
}
F greetings
问题:
思路:贪心后就是逆序对板子,可用树状数组,归并排序求解,这里是树状数组
问题:在离散化二分时,由于要把离散化内容控制在1到a.size()范围内,因此这里人为的将下标向右偏移一个单位,所以在二分调时用mid查找元素时,要将这个偏移量去掉 详见find函数中A[mid - 1]
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
const int N = 2e5 + 10;
typedef pair<int, int> PII;
int n;
int a[N], b[N];
PII node[N];
int tr[N << 1];
int lowbit(int x) {
return x & -x;
}
void add(int x) {
for(int i = x; i <= n + n; i += lowbit(i)) {
tr[i] ++;
}
}
int query(int x) {
int sum = 0;
for(int i = x; i >= 1; i -= lowbit(i)) sum += tr[i];
return sum;
}
int find(int x, vector<int> &A) {
int l = 1, r = A.size();
while(l < r) {
int mid = l + r >> 1;
if(A[mid - 1] >= x) r = mid;
else l = mid + 1;
}
return l;
}
void solve() {
vector<int> pos;
memset(tr, 0, sizeof tr);
cin >> n;
for(int i = 1; i <= n; i ++ ) {
int a, b;
cin >> a >> b;
node[i] = {a, b};
pos.push_back(b);
}
sort(node + 1, node + 1 + n);
sort(pos.begin(), pos.end());
//pos.erase(unique(pos.begin(), pos.end()), pos.end());
long long ans = 0;
//cout << query(find(1, pos) + n);
for(int i = n; i >= 1; i -- ) {
int t = query(find(node[i].second, pos) + n);
ans += t;
add(find(node[i].second, pos) + n);
}
cout << ans << endl;
}
int main() {
int t;
cin >> t;
while(t -- ) {
solve();
}
return 0;
}
G bicycles
问题:
代码一直报错,明天补题....