C: Error Correction
显然只有当行、列各有一个不满足条件时可以change bit。
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200 + 10;
int main()
{
int n;
while (cin >> n && n != 0)
{
int c[maxn], w[maxn];
int maze[maxn][maxn];
set<int> cc, ww;
for (int i = 1; i <= n; i++)
{
c[i] = 0;
for (int j = 1; j <= n; j++)
{
cin >> maze[i][j];
c[i] += maze[i][j];
}
if (c[i] % 2 == 1)
cc.insert(i);
}
for (int i = 1; i <= n; i++)
{
w[i] = 0;
for (int j = 1; j <= n; j++)
w[i] += maze[j][i];
if (w[i] % 2 == 1)
ww.insert(i);
}
if (ww.size() + cc.size() == 0)
cout << "OK" << endl;
else if (ww.size() != 1 || cc.size() != 1)
cout << "Corrupt" << endl;
else
printf("Change bit (%d,%d)\n", *cc.begin(), *ww.begin());
}
}
E: Soundex
模拟即可。
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 10;
int idx;
int a[29] = {0, 1, 2, 3, 0, 1, 2, 0, 0, 2, 2, 4, 5, 5, 0, 1, 2, 6, 2, 3, 0, 1, 0, 2, 0, 2};
int main()
{
string s;
while (cin >> s)
{
set<pair<int, int>> st;
int n = s.size();
for (int i = 0; i < n; i++)
if (a[(s[i] - 'A')] != 0)
st.insert(make_pair(i, a[(s[i] - 'A')]));
int last = -2, lastx = -1;
for (auto x : st)
{
if (x.first - last > 1 || x.second != lastx)
cout << x.second;
last = x.first;
lastx = x.second;
}
cout << endl;
}
}
F: Antiarithmetic
给定一个长为n的数组,问是否存在等差数列。
记录每个元素出现的下标idx,枚举公差。
(等差数列两要素:公差和其中一项确定一个等差数列)
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int idx[maxn];
int main()
{
int n;
char e;
while (cin >> n && n != 0 && cin >> e)
{
for (int i = 0; i < n; i++)
{
int x;
cin >> x;
idx[x] = i;
}
bool flag = false;
for (int i = 1; i < n - 1; i++)
{
int minx = min(n - 1 - i, i);
for (int j = 1; j <= minx; j++)
{
if ((idx[i + j] - idx[i]) * (idx[i - j] - idx[i]) < 0)
{
flag = true;
cout << "no" << endl;
break;
}
}
if (flag)
break;
}
if (!flag)
cout << "yes" << endl;
}
}
G: Only I did it!
给定三个学生完成的问题编号,求完成独一无二的问题最多的学生(独一无二的问题指只有一个人做出来的问题)
模拟即可。
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
long long a[maxn];
int idx;
void solve()
{
//s12表示学生1和学生2完成的题目,用于筛选出学生3完成的独一无二的题目,以此类推。
//s[i]保存第i给学生完成的独一无二的题目。
set<int> s12, s23, s13, s[4];
int n1, n2, n3;
//------------分别输入三个学生完成的问题-------------
cin >> n1;
for (int i = 1; i <= n1; i++)
{
int x;
cin >> x;
s[1].insert(x);
s13.insert(x);
s12.insert(x);
}
cin >> n2;
for (int i = 1; i <= n2; i++)
{
int x;
cin >> x;
s[2].insert(x);
s23.insert(x);
s12.insert(x);
}
cin >> n3;
for (int i = 1; i <= n3; i++)
{
int x;
cin >> x;
s[3].insert(x);
s13.insert(x);
s23.insert(x);
}
//---------------------------------------------
//-------筛选出每个学生完成的独一无二的问题-------
for (auto x : s23)
s[1].erase(x);
for (auto x : s13)
s[2].erase(x);
for (auto x : s12)
s[3].erase(x);
//----------------------------------------------
//-------找到解决独一无二问题最多的学生----------
int maxx = 1;
for (int i = 2; i <= 3; i++)
if (s[i].size() > s[maxx].size())
maxx = i;
//---------------------------------------------
//---------如果最大值相同则按学生顺序输出---------
cout << "Case #" << ++idx << ":" << endl;
for (int i = 1; i <= 3; i++)
{
if (s[i].size() == s[maxx].size())
{
cout << i << " ";
cout << s[i].size() << " ";
for (auto y : s[i])
cout << y << " ";
cout << endl;
}
}
//------------------------------
}
int main()
{
int t;
cin >> t;
while (t--)
{
solve();
}
}
H: Square Numbers
签到题
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
long long a[maxn];
int idx;
int main()
{
int a, b, res = 0;
while (cin >> a >> b)
{
res=0;
if (a == 0 && b == 0)
return 0;
int i;
for (i = 1;; i++)
{
if (i * i > b)
break;
if (i * i >= a)
res++;
}
cout << res << endl;
}
}
I: 面积
签到题
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int main()
{
long long res=0;
cin.tie();
int n;
cin>>n;
while(n--)
{
long long a,b;
cin>>a>>b;
res += a * b;
}
cout << res;
}
J: 分数
签到题。
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
long long a[maxn];
int main()
{
long long res = 0;
cin.tie();
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
sort(a + 1, a + 1 + n);
for (int i = 1; i <= n; i++)
res += i * a[i];
cout << res;
}