ACM模版
这个比赛早就知道有,但是因为自己要骑行,结果就没有注册,后来骑行计划延期,但是也忘了注册,赛后重现赛尝试做了 12 道,感觉水题比较多,剩下三个 AC 的人好少啊,感觉我这么菜肯定也是做不出来,所以就先不补了吧……
水题,扫描一遍就行了。
#include
#include
#include
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;
}
模拟题,注意细节就好了。
#include
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;
}
扫描一遍,计数就行了。
#include
#include
#include
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;
}
简单的组合,输出 2n−1 2 n − 1 即可,快速幂。
#include
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;
}
数学题,先转化为十进制,然后短除法即可。
#include
#include
#include
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;
}
说白了,就是左右各一遍 LIS 即可。模版题~~~
#include
#include
#include
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;
}
直接暴力,dfs 出来所有情况,判断是否有合理情况存在即可。
#include
#include
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;
}
预处理>>>
记忆化搜索>>>
数论推导>>>
二分贪心>>>
线段树>>>