# 2018年哈尔滨工程大学ACM校赛

• 2018-04-15
• 3,539
• 1
• 1

【2018-05-01更新】校赛题目已经挂到OJ：https://oj.zjw1.top/problemset.php?page=3（2019.6.4更：该网站到期未续费，现已无法访问），题目id 1219~1231

# 题解

## 1. T13

``````#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

int main()
{
int t, a, b, c;
scanf("%d", &t);
while (t--)
{
scanf("%d%d%d", &a, &b, &c);
printf("%d\n", a*b+c);
}

return 0;
}
``````

## 2. T3

``````#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

int main()
{
printf("Our lab is aimed at taking part in the competitions regarding the programming, especially on algorithm.A series of the competitions requires the participants doing well in using the programming skills, which are attractive to those internet companies.Thus getting on with the competitions means that you have advantages to compete with other candidates.So do the interviews for postgraduates.Now, be a winner\"\\\\(\%_\%)//``And good luck!By the way, our lab is located at 21B\\573.");

return 0;
}
``````

## 3. T1

``````#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

int main()
{
int t, n, ans;
scanf("%d", &t);
while (t--)
{
ans = 0;
scanf("%d", &n);
while (n)
{
ans += n /= 5;
}
printf("%d\n", ans);
}

return 0;
}
``````

## 4. T6

``````#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
typedef long long LL;
using namespace std;
LL a[10][10], A[10][10];

int main()
{
int t;
scanf("%d", &t);
while (t--)
{
for (int i = 1; i <= 3; i++)
{
for (int j = 1; j <= 3; j++)
{
scanf("%lld", &A[i][j]);
}
}
a[1][1] = A[2][2]*A[3][3]-A[2][3]*A[3][2];
a[1][2] = A[2][3]*A[3][1]-A[2][1]*A[3][3];
a[1][3] = A[2][1]*A[3][2]-A[2][2]*A[3][1];
a[2][1] = A[1][3]*A[3][2]-A[1][2]*A[3][3];
a[2][2] = A[1][1]*A[3][3]-A[1][3]*A[3][1];
a[2][3] = A[1][2]*A[3][1]-A[1][1]*A[3][2];
a[3][1] = A[1][2]*A[2][3]-A[1][3]*A[2][2];
a[3][2] = A[1][3]*A[2][1]-A[1][1]*A[2][3];
a[3][3] = A[2][2]*A[1][1]-A[2][1]*A[1][2];

for (int i = 1; i <= 3; i++)
{
for (int j = 1; j <= i; j++)
{
swap(a[i][j], a[j][i]);
}
}
printf("%lld\n", a[1][1]*a[2][2]*a[3][3]-a[1][1]*a[2][3]*a[3][2]-a[1][2]*a[2][1]*a[3][3]+a[1][2]*a[2][3]*a[3][1]+a[1][3]*a[2][1]*a[3][2]-a[1][3]*a[2][2]*a[3][1]);
}

return 0;
}
``````

## 5. T5

``````#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int num[1000006] = {0};

int main()
{
int t = 1, n = 1, a, b, f = 1;
while (t < 1000003)
{
if (f) num[t] = 1, f = !f, t++;
else
{
t += n*2;
n++;
f = !f;
}
}
scanf("%d", &t);
while (t--)
{
int ans = 0;
scanf("%d%d%d", &n, &a, &b);
for (int i = a; i <= b; i++)
{
if (num[i] == 0) ans++;
}
printf("%d\n", ans);
}

return 0;
}
``````

## 6. T9

``````#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
typedef long long LL;
using namespace std;
LL a, b, c, ll, rr;

LL f(LL x)
{
return a*x*x + b*x + c;
}

int main()
{
int t;
LL f_min, f_max;
scanf("%d", &t);
while (t--)
{
scanf("%lld%lld%lld%lld%lld", &a, &b, &c, &ll, &rr);
if (ll > rr) swap(ll, rr);
if (a > 0)
{
LL tt = -b / (2*a);
//cout<<tt<<endl;  /// 只是因为这一行忘了删了，并且在最后比较急躁，没有发现这个问题。
f_min = min(f(ll), f(rr));
f_max = max(f(ll), f(rr));
if (tt >= ll && tt <= rr) f_min = min(f_min, f(tt));
if (tt-1 >= ll && tt-1 <= rr) f_min = min(f_min, f(tt-1));
if (tt+1 >= ll && tt+1 <= rr) f_min = min(f_min, f(tt+1));
}else if (a < 0)
{
LL tt = -b / (2*a);
f_max = max(f(ll), f(rr));
f_min = min(f(ll), f(rr));
if (tt >= ll && tt <= rr) f_max = max(f_max, f(tt));
if (tt-1 >= ll && tt-1 <= rr) f_max = max(f_max, f(tt-1));
if (tt+1 >= ll && tt+1 <= rr) f_max = max(f_max, f(tt+1));
}else { if (b > 0)
{
f_max = f(rr);
f_min = f(ll);
}
else
{
f_max = f(ll);
f_min = f(rr);
}
}
printf("%lld %lld\r\n", f_max, f_min);
}

return 0;
}
``````

## 7. T2

``````#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
using namespace std;
char is_q = 0, is_c = 0;  // is_q表示是否在引号中间（单引号及双引号），is_c表示是否在段落注释中间（/*...*/）
string s[100001];

int main()
{
int cnt = 0;
while(getline(cin, s[cnt])) cnt++;
for (int i = 0; i < cnt; i++)
{
int len = s[i].length();
for (int j = 0; j < len; j++)
{
if (!is_q)
{
if (!is_c && s[i][j] == '"') is_q = '"';
if (!is_c && s[i][j] == '\'') is_q = '\'';
if (!is_c && s[i][j] == '/' && s[i][j+1] == '/')
{
break;
}
if (!is_c && s[i][j] == '/' && s[i][j+1] == '*')
{
is_c = 1;
putchar(' ');
}
if (s[i][j-1] == '*' && s[i][j] == '/') is_c = 0;
else if (!is_c) putchar(s[i][j]);
}else
{
while (s[i][j] == '\\')  // 之前这里写的是if,就错了
{
putchar(s[i][j]);
putchar(s[i][j+1]);
j += 2;
}
if (is_q == '"' && s[i][j] == '"')
{
is_q = 0;
}
if (is_q == '\'' && s[i][j] == '\'')
{
is_q = 0;
}
putchar(s[i][j]);
}
}
if (!is_c) printf("\n");

}

return 0;
}
``````

## T12. 后缀数组处理字符串

#### 评论

• ###### XDL 2018-04-16 10:59回复

不菜，我才准备开始学算法……