SHU-“盛大遊戲杯”第15屆上海大學程式設計聯賽夏季賽暨上海高校金馬五校賽-A~K && M
阿新 • • 發佈:2019-02-18
這個比賽早就知道有,但是因為自己要騎行,結果就沒有註冊,後來騎行計劃延期,但是也忘了註冊,賽後重現賽嘗試做了 12 道,感覺水題比較多,剩下三個 AC 的人好少啊,感覺我這麼菜肯定也是做不出來,所以就先不補了吧……
A-黑白影象直方圖
描述
題解
水題,掃描一遍就行了。
程式碼
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN = 111;
int n, m;
int cnt[MAXN];
int main(int argc, const char * argv[])
{
while (cin >> n >> m)
{
memset(cnt, 0, sizeof(cnt));
int x;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
scanf("%d", &x);
if (x)
{
cnt[j]++;
}
}
}
printf ("%d", cnt[0]);
for (int j = 1; j < m; j++)
{
printf(" %d", cnt[j]);
}
putchar(10);
}
return 0;
}
B-神無月排位賽
描述
題解
模擬題,注意細節就好了。
程式碼
#include <iostream>
using namespace std;
int N;
int main(int argc, const char * argv[])
{
int level, score;
while (cin >> N)
{
level = 3;
score = 0;
int x, y;
for (int i = 0; i < N; i++)
{
scanf("%d", &x);
if (x)
{
score += 10;
}
else
{
score -= 5;
}
if (score < 0)
{
score = 0;
}
if (score >= 100)
{
if (i + 2 >= N)
{
continue;
}
scanf("%d%d", &x, &y);
if (x == y)
{
if (x)
{
level--;
score = 0;
}
else
{
score = 60;
}
i += 2;
continue;
}
if (i + 3 >= N)
{
continue;
}
scanf("%d", &x);
if (x)
{
level--;
score = 0;
}
else
{
score = 60;
}
i += 3;
}
}
if (level < 0)
{
puts("S");
}
else
{
putchar('A' + level);
putchar(10);
}
}
return 0;
}
C-I Love ces
描述
題解
掃描一遍,計數就行了。
程式碼
#include <iostream>
#include <cstring>
#include <string>
using namespace std;
const int MAXN = 100;
const int MAGIC = 32;
const int INF = 0x3f3f3f3f;
string s;
int cnt[MAXN];
int main(int argc, const char * argv[])
{
while (cin >> s)
{
memset(cnt, 0, sizeof(cnt));
int len = (int)s.length();
for (int i = 0; i < len; i++)
{
if (s[i] >= 'a')
{
s[i] -= MAGIC;
}
cnt[s[i]]++;
}
cnt['E'] /= 2;
int res = INF;
res = min(res, cnt['I']);
res = min(res, cnt['L']);
res = min(res, cnt['O']);
res = min(res, cnt['V']);
res = min(res, cnt['E']);
res = min(res, cnt['C']);
res = min(res, cnt['S']);
cout << res << '\n';
}
return 0;
}
D-新增好友
描述
題解
簡單的組合,輸出 即可,快速冪。
程式碼
#include <iostream>
using namespace std;
const int MOD = 1e9 + 7;
typedef long long ll;
ll QPow(ll x, ll n)
{
ll ret = 1;
ll tmp = x % MOD;
while (n)
{
if (n & 1)
{
ret = (ret * tmp) % MOD;
}
tmp = tmp * tmp % MOD;
n >>= 1;
}
return ret;
}
int n;
int main(int argc, const char * argv[])
{
while (cin >> n)
{
cout << QPow(2, n) - 1 << '\n';
}
return 0;
}
E-字串進位制轉換
描述
題解
數學題,先轉化為十進位制,然後短除法即可。
程式碼
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
const int MAXN = 15;
const int MAGIC = 26;
int m;
ll POW[MAXN] = {1};
string A;
void init()
{
for (int i = 1; i < MAXN; i++)
{
POW[i] = POW[i - 1] * MAGIC;
}
}
int main(int argc, const char * argv[])
{
init();
while (cin >> A >> m)
{
ll num = 0;
for (int i = (int)A.length() - 1, j = 0; i >= 0; i--, j++)
{
num += (A[i] - 'a') * POW[j];
}
if (num == 0)
{
cout << "0\n";
continue;
}
string ans;
while (num)
{
ans.push_back(num % m + '0');
num /= m;
}
reverse(ans.begin(), ans.end());
cout << ans << '\n';
}
return 0;
}
F-A序列
描述
題解
說白了,就是左右各一遍 LIS 即可。模版題~~~
程式碼
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
/*
* 遞增(預設)
* 遞減
* 非遞增
* 非遞減 (1)>= && < (2)< (3)>=
*/
const int MAXN = 5e5 + 10;
int a[MAXN], f[MAXN], d[MAXN], d_[MAXN]; // d[i] 用於記錄 a[0...i] 以 a[i] 結尾的最大長度
int bsearch(const int *f, int size, const int &a)
{
int l = 0, r = size - 1;
while (l <= r)
{
int mid = (l + r) / 2;
if (a > f[mid - 1] && a <= f[mid]) // (1)
{
return mid;
}
else if (a < f[mid])
{
r = mid - 1;
}
else
{
l = mid + 1;
}
}
return -1;
}
int LIS(const int *a, int *d, const int &n)
{
int i, j, size = 1;
f[0] = a[0];
d[0] = 1;
for (i = 1; i < n; ++i)
{
if (a[i] <= f[0]) // (2)
{
j = 0;
}
else if (a[i] > f[size - 1]) // (3)
{
j = size++;
}
else
{
j = bsearch(f, size, a[i]);
}
f[j] = a[i];
d[i] = j + 1;
}
return size;
}
int main()
{
int i, n;
while (scanf("%d", &n) != EOF)
{
for (i = 0; i < n; ++i)
{
scanf("%d", &a[i]);
}
LIS(a, d, n);
reverse(a, a + n);
LIS(a, d_, n);
int res = 1;
for (int i = 0; i < n; i++)
{
if (d[i] <= d_[n - i - 1])
{
res = max(res, (d[i] << 1) - 1);
}
else
{
res = max(res, (d_[n - i - 1] << 1) - 1);
}
}
cout << res << '\n';
}
return 0;
}
G-戰鬥
描述
題解
直接暴力,dfs 出來所有情況,判斷是否有合理情況存在即可。
程式碼
#include <iostream>
#include <cstring>
using namespace std;
const int MAXN = 11;
struct node
{
int v, a;
} my[MAXN], sy[MAXN];
int n;
int rk[MAXN], vis[MAXN];
bool judge()
{
int i = 0, j = 0;
node a = sy[i], b = my[rk[j]];
while (i < n && j < n)
{
int t1 = a.v / b.a;
int t2 = b.v / a.a;
int x = min(t1, t2);
a.v -= b.a * x;
b.v -= a.a * x;
while (a.v > 0 && b.v > 0)
{
a.v -= b.a;
b.v -= a.a;
}
if (a.v <= 0)
{
a = sy[++i];
}
if (b.v <= 0)
{
b = my[rk[++j]];
}
}
return j == n ? false : true;
}
bool dfs(int pos)
{
if (pos == n)
{
if (judge())
{
return true;
}
return false;
}
for (int i = 0; i < n; i++)
{
if (!vis[i])
{
rk[pos] = i;
vis[i] = 1;
if (dfs(pos + 1))
{
return true;
}
vis[i] = 0;
}
}
return false;
}
int main()
{
int T;
scanf("%d", &T);
while (T--)
{
memset(vis, 0, sizeof(vis));
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
scanf("%d%d", &sy[i].v, &sy[i].a);
}
for (int i = 0; i < n; i++)
{
scanf("%d%d", &my[i].v, &my[i].a);
}
if (dfs(0))
{
printf("YES\n");
}
else
{
printf("NO\n");
}
}
return 0;
}
H-調和序列
預處理>>>
I-丟史蒂芬妮
記憶化搜尋>>>
J-膜一下將帶給你好運
數論推導>>>
K-購買裝備
二分貪心>>>
M-風力觀測
線段樹>>>