2015-2016 ACM-ICPC, NEERC, Northern Subregional Contest
作者:互联网
2015-2016 ACM-ICPC, NEERC, Northern Subregional Contest
A - Alex Origami Squares
长为h, 宽为w
如果w * 3 > h,则正方体边长为w
如果w * 3 < h,则正方体边长为max(h / 3, w / 2)
#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
using namespace std;
string a, b, c;
int main()
{
freopen("alex.in", "r", stdin);
freopen("alex.out", "w", stdout);
cin.tie(0)->sync_with_stdio(0);
double a, b;
cin >> a >> b;
if (a < b)
swap(a, b);
double ans;
ans = a / 3;
if (a > b * 3)
ans = b;
ans = max(ans, b / 2);
printf("%.3lf", ans);
fclose(stdin);
fclose(stdout);
return 0;
}
B - Black and White
给出两个数,分别代表黑色连续地砖的数量和白色连续地砖的数量,输出代表黑色连续地砖和白色连续地砖的矩阵
#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
using namespace std;
int main()
{
freopen("black.in", "r", stdin);
freopen("black.out", "w", stdout);
// cin.tie(0)->sync_with_stdio(0);
int b, w;
cin >> b >> w;
if(b > w)
{
int t = b - w;
t++;
cout << t * 2 + (w - 1) * 2<< ' ' << 2 << endl;
while(t--) //先输出多出来的b-w+1个黑色区域
{
cout << '@' << '.' << endl;
cout << '.' << '.' << endl;
}
w--;
while(w--)//输出剩余部分
{
cout << '@' << '@' << endl;
cout << '.' << '.' << endl;
}
}
else
{
int t = w - b;
t++;
cout << t * 2 + (b - 1) * 2 << ' ' << 2 << endl;
while(t--)
{
cout << '.' << '@' << endl;
cout << '@' << '@' << endl;
}
b--;
while (b--) {
cout << '.' << '.' << endl;
cout << '@' << '@' << endl;
}
}
fclose(stdin);
fclose(stdout);
return 0;
}
C - Concatenation
给定两个字符串,寻找第一个字符串的前缀和的二哥字符串的后缀组成不同字符窜的个数
通过样例二,可以得出,当有字符多次出现在一个字符串之中时,必然有重复,但是,我们可以通过痛苦的分析可以得出:字符串的重复与第一个字符串的首字符以及的二哥字符串的尾字符无关
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
typedef long long ll;
ll a[N];
map<char, ll> q;
map<char, ll> p;
int main()
{
freopen("concatenation.in", "r", stdin);
freopen("concatenation.out", "w", stdout);
string a, b;
cin >> a >> b;
ll len1 = a.size();
ll len2 = b.size();
for (int i = 1; i < len1; i++)
q[a[i]]++;
for (int i = 0; i + 1 < len2; i++)
p[b[i]]++;
ll ans = len1 * len2;
for (char i = 'a'; i <= 'z'; i++) {
ans -= p[i] * q[i];
}
cout << ans << endl;
fclose(stdin);
fclose(stdout);
return 0;
}
E - Easy Arithmetic
这道题只需注意一个点,例如-302000应该拆成-3 + 0 + 2000
#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
using namespace std;
string a, b, c;
int main()
{
freopen("easy.in", "r", stdin);
freopen("easy.out", "w", stdout);
// cin.tie(0)->sync_with_stdio(0);
string c;
cin >> c;
int l = c.size();
bool flag = 1;
for (int i = 0; i < l; i++) {
if (c[i] == '+')
flag = 1;
else if (c[i] == '-')
flag = 0;
else {
if (!flag && c[i - 1] != '-' && c[i - 1] != '+' && c[i] == '0')
cout << '+';
if (!flag && c[i - 1] != '-' && c[i - 1] != '+' && c[i] != '0') {
cout << '+';
flag = 1;
}
}
cout << c[i];
}
fclose(stdin);
fclose(stdout);
return 0;
}
H - Hash Code Hacker
通过样例,不难得出,每个字符串都是者32位进制字符串,所以我们可以通过初始化一个字符串,将其第一位减1,第二位加31,也可以倒过来,然后回复原样,向后移动一位
#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
using namespace std;
string a, b, c;
int main()
{
freopen("hash.in", "r", stdin);
freopen("hash.out", "w", stdout);
cin.tie(0)->sync_with_stdio(0);
int n;
cin >> n;
for (int i = 0; i < n; i++)
a += 'B';
cout << a << endl;
for (int i = 0; i < n - 1; i++) {
a[i] = 'A';
a[i + 1] = 'a';
cout << a << endl;
a[i] = 'B';
a[i + 1] = 'B';
}
fclose(stdin);
fclose(stdout);
return 0;
}
L - Lucky Chances
数据范围为100 * 100,可以通过枚举求解,分别向上,下,左,右四个方向进行扩展,如果不符合条件,那么直接返回即可
#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
using namespace std;
int a[110][110], r, c, ans;
int dx[] = { 0, 0, 1, -1 }, dy[] = { 1, -1, 0, 0 };
bool find(int b, int x, int y, int n, int m)
{
x += n, y += m;
while (x >= 0 && y >= 0 && x <= r + 1 && y <= c + 1) {
if (b <= a[x][y])
return 0;
x += n, y += m;
}
return 1;
}
int main()
{
freopen("lucky.in", "r", stdin);
freopen("lucky.out", "w", stdout);
// cin.tie(0)->sync_with_stdio(0);
cin >> r >> c;
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= c; j++)
cin >> a[i][j];
}
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= c; j++) {
for (int k = 0; k < 4; k++) {
if (find(a[i][j], i, j, dx[k], dy[k])) {
ans++;
}
}
}
}
cout << ans << endl;
fclose(stdin);
fclose(stdout);
return 0;
}
标签:Northern,Contest,int,Subregional,cin,freopen,ans,字符串,include 来源: https://www.cnblogs.com/Flying-bullet/p/16531014.html