2018 Multi-University Training Contest 1 Solution
A - Maximum Multiple
题意:给出一个n 找x, y, z 使得$n = x + y +z$ 并且 $n \equiv 0 \pmod x, n \equiv 0 \pmod y, n \equiv 0 \pmod z$ 并且使得 $x \cdot y \cdot z$ 最大
思路:设$a = \frac{n}{x}, b = \frac{n}{y}, c = \frac{n}{z}$ 那么 $\frac{1}{a} + \frac{1}{b} + \frac{1}{c} = 1$ 那么我们考虑去凑 a, b, c
两种方案 ${3, 3, 3}$ 或者 ${2, 4, 4}$ 取max
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll n; int main()
{
int t;
scanf("%d", &t);
while(t--)
{
scanf("%lld", &n);
if(n % == )
{
ll ans = n / ;
ans *= n / ;
ans *= n / ;
printf("%lld\n", ans);
}
else if(n % == )
{
ll ans = n / ;
ans *= n / ;
ans *= n / ;
printf("%lld\n", ans);
}
else
{
puts("-1");
}
}
return ;
}
B - Balanced Sequence
题意:求如何拼接 使得balanced Sequence 最长
思路:首先预处理,使得剩下的串都是 ((( 或者 ))) 或者 )))(((
((( 这种都放左边 ))) 都放右边 目前的问题就是 )))((( 这种在中间按什么顺序放使得答案最大
我们定义 $L_1, R_1$ $L_2, R_2$ 分别为两个串的左括号数量和右括号数量
假如 1 放在 2前面 那么对答案的贡献是 $min(R_1, L_2)$
假如 1 放在 2 后面 那么对答案的贡献是 $min(R_2, L_1)$
比较对答案的贡献,哪个答案贡献大,选哪种放置方式
如果读答案的贡献一样大,那么我们让左括号多的放前面 因为这样对后面的答案贡献大
Dup4:
#include <bits/stdc++.h> using namespace std; #define N 100010 struct node
{
int l, r;
inline node() {}
inline node(int l, int r) : l(l), r(r) {}
inline bool operator < (const node &b) const
{
int t1 = min(l, b.r), t2 = min(r, b.l);
return t1 > t2 || (t1 == t2 && (l > b.l));
}
}arr[N]; int t, n;
char s[N]; int main()
{
scanf("%d", &t);
while (t--)
{
int L = , R = , ans = , cnt = ;
scanf("%d", &n);
for (int i = ; i <= n; ++i)
{
scanf("%s", s);
int LL = , RR = ;
for (int j = , len = strlen(s); j < len; ++j)
{
if (s[j] == '(')
++LL;
else
{
if (LL)
{
--LL;
ans += ;
}
else
++RR;
}
}
if (LL && RR)
arr[++cnt] = node(LL, RR);
else if (LL) L += LL;
else R += RR;
}
sort(arr + , arr + + cnt);
for (int i = ; i <= cnt; ++i)
{
int LL = arr[i].l, RR = arr[i].r;
ans += min(L, RR) * ;
L -= min(L, RR);
L += LL;
}
ans += min(L, R) * ;
printf("%d\n", ans);
}
return ;
}
XHT:
#include <bits/stdc++.h> using namespace std; #define N 100010 struct node
{
int l, r;
inline node() {}
inline node(int l, int r) : l(l), r(r) {}
inline bool operator < (const node &b) const
{
if(l >= r && b.l < b.r)
return true;
if(l < r && b.l >= b.r)
return false;
if(l >= r && b.l >= b.r)
return r < b.r;
if(l < r && b.l < b.r)
return l > b.l;
}
}arr[N]; int t, n;
char s[N]; int main()
{
scanf("%d", &t);
while (t--)
{
int ans = ;
scanf("%d", &n);
for (int i = ; i <= n; ++i)
{
scanf("%s", s);
int LL = , RR = ;
for (int j = , len = strlen(s); j < len; ++j)
{
if (s[j] == '(')
++LL;
else
{
if (LL)
{
--LL;
ans += ;
}
else
++RR;
}
}
arr[i] = node(LL, RR);
}
sort(arr + , arr + + n);
int L = ;
for (int i = ; i <= n; ++i)
{
int LL = arr[i].l, RR = arr[i].r;
ans += min(L, RR) * ;
L -= min(L, RR);
L += LL;
}
printf("%d\n", ans);
}
return ;
}
C - Triangle Partition
水.(排序)
#include<bits/stdc++.h> using namespace std; const int maxn = 1e3 + ; struct node{
int x, y, id;
inline node(){}
inline node(int x, int y, int id):x(x), y(y), id(id){}
inline bool operator < (const node &b) const
{
return x == b.x ? y < b.y : x < b.x;
}
}P[maxn << ]; int n; int main()
{
int t;
scanf("%d", &t);
while(t--)
{
scanf("%d", &n);
for(int i = ; i <= * n; ++i)
{
scanf("%d %d", &P[i].x, &P[i].y);
P[i].id = i;
}
sort(P + , P + + * n);
for(int i = ; i <= * n; i += )
{
printf("%d %d %d\n", P[i].id, P[i + ].id, P[i + ].id);
}
}
return ;
}
D - Distinct Values
按题意模拟即可。
#include <bits/stdc++.h> using namespace std; #define N 100010 struct node
{
int l, r;
inline void scan()
{
scanf("%d%d", &l, &r);
}
inline bool operator < (const node &r) const
{
return l < r.l || (l == r.l && this->r > r.r);
}
}Data[N]; int t, n, m;
int ans[N];
bool vis[N];
int R; int main()
{
scanf("%d", &t);
while (t--)
{
memset(ans, , sizeof ans);
R = ;
scanf("%d%d", &n, &m);
for (int i = ; i <= m; ++i) Data[i].scan();
sort(Data + , Data + + m);
for (int i = ; i <= m; ++i)
{
int l = Data[i].l, r = Data[i].r;
if (R >= r) continue;
if (R + < l)
for (int j = R + ; j < l; ++j) ans[j] = ;
memset(vis, false, sizeof vis);
for (int j = l; j <= R; ++j) vis[ans[j]] = true;
int L = ;
for (int j = max(R + , l); j <= r; ++j)
{
while (vis[L]) ++L;
ans[j] = L;
vis[L] = true;
}
R = max(R, r);
}
while (R < n)
{
R++;
ans[R] = ;
}
for (int i = ; i <= n; ++i) printf("%d%c", ans[i], " \n"[i == n]);
}
return ;
}
E - Maximum Weighted Matching
留坑。
F - Period Sequence
留坑。
G - Chiaki Sequence Revisited
题意:定义$a_n$ 求 $\sum_{i = 1} ^ {i = n} a_i$
思路:先不考虑$a_1$
我们对每个最后一个2的幂次数处理出它前面有多少个数, 以及这些数的前缀和是多少
比如说处理出
1 2 4 8 16
1 3 7 15 31
1 5 20 76 288
然后给出n计算的时候 按二进制拆分 比如说
27 = 15 + 7 + 3 + 3
定义$F[i] 为 前面i个数的前缀和$
$ans[27] = F[15] + F[7] + 7 * 8 + F[3] + 3 * (8 + 2) + F[3] + 3 * (8 + 2 + 2)$
对于后面,相当于所有数向右偏移
注意取模
#include <bits/stdc++.h> using namespace std; #define N 64
#define ll long long const ll MOD = (ll)1e9 + ; int t;
ll n;
ll a[N], b[N], c[N]; inline void Init()
{
a[] = ;
for (int i = ; i <= ; ++i) a[i] = a[i - ] << ;
b[] = ;
for (int i = ; i <= ; ++i) b[i] = (b[i - ] << ) + ;
c[] = ;
for (int i = ; i <= ; ++i) c[i] = ((c[i - ] << ) % MOD + (a[i - ] % MOD) * (b[i - ] % MOD) % MOD + a[i]) %MOD;
// for (int i = 0; i <= 59; ++i) printf("%lld %lld %lld\n", a[i], b[i], c[i]);
} int main()
{
Init(); scanf("%d", &t);
while (t--)
{
scanf("%lld", &n); --n;
ll ans = , tmp = ;
for (int i = ; i >= ; --i)
{
while (n >= b[i])
{
ans = (ans + c[i]) % MOD;
ans = (ans + (b[i] % MOD * tmp) % MOD) % MOD;
tmp = (tmp + a[i]) % MOD;
n -= b[i];
}
}
printf("%lld\n", ans);
}
return ;
}
H - RMQ Similar Sequence
留坑。
I - Lyndon Substring
留坑。
J - Turn Off The Light
留坑。
K - Time Zone
按题意模拟即可
#include <bits/stdc++.h> using namespace std; int t, a, b;
char s[]; inline void work1()
{
int ans = ; int flag = ;
if (s[] == '-')
flag = -;
int len = strlen(s);
for (int i = ; i < len; ++i)
ans = ans * + s[i] - '';
ans *= flag;
int gap = ans - ;
a = (a + gap + ) % ;
printf("%02d:%02d\n", a, b);
return;
} inline void work2()
{
int A = , B = ; int flag = ;
if (s[] == '-')
flag = -;
int len = strlen(s), i;
for (i = ; s[i] != '.'; ++i)
A = A * + s[i] - '';
for (++i; i < len; ++i)
B = B * + s[i] - '';
int tot = a * + b;
A *= flag, B = B * * flag;
int tmptot = A * + B - ;
tot = (tot + tmptot + * ) % ( * );
printf("%02d:%02d\n", tot / , tot % );
return;
} int main()
{
scanf("%d", &t);
while (t--)
{
scanf("%d %d UTC%s", &a, &b, s);
bool flag = true;
for (int i = , len = strlen(s); i < len; ++i)
if (s[i] == '.')
{
flag = false;
break;
}
if (flag) work1();
else work2();
}
return ;
}
2018 Multi-University Training Contest 1 Solution的更多相关文章
- 2018 Multi-University Training Contest 2 Solution
A - Absolute 留坑. B - Counting Permutations 留坑. C - Cover 留坑. D - Game puts("Yes") #include ...
- 2018 Multi-University Training Contest 3 Solution
A - Problem A. Ascending Rating 题意:给出n个数,给出区间长度m.对于每个区间,初始值的max为0,cnt为0.遇到一个a[i] > ans, 更新ans并且cn ...
- 2018 Multi-University Training Contest 4 Solution
A - Problem A. Integers Exhibition 留坑. B - Problem B. Harvest of Apples 题意:计算$\sum_{i = 0}^{i = m}C( ...
- 2018 Multi-University Training Contest 5 Solution
A - Always Online Unsolved. B - Beautiful Now Solved. 题意: 给出一个n, k 每次可以将n这个数字上的某两位交换,最多交换k次,求交换后的最大 ...
- 2018 Multi-University Training Contest 6 Solution
A - oval-and-rectangle 题意:给出一个椭圆的a 和 b,在$[0, b]中随机选择c$ 使得四个顶点在椭圆上构成一个矩形,求矩形周长期望 思路:求出每种矩形的周长,除以b(积分) ...
- 2018 Multi-University Training Contest 7 Solution
A - Age of Moyu 题意:给出一张图,从1走到n,如果相邻两次走的边的权值不同,花费+1, 否则花费相同,求最小花费 思路:用set记录有当前点的最小花费有多少种方案到达,然后最短路 #i ...
- 2018 Multi-University Training Contest 8 Solution
A - Character Encoding 题意:用m个$0-n-1$的数去构成k,求方案数 思路:当没有0-n-1这个条件是答案为C(k+m-1, m-1),减去有大于的关于n的情况,当有i个n时 ...
- 2018 Multi-University Training Contest 9 Solution
A - Rikka with Nash Equilibrium 题意:构造一个$n * m$的矩阵,使得$[1, n * m]$ 中每个数只出现一次,并且纳什均衡只出现一次. 思路:从大到小的放置,每 ...
- 2018 Multi-University Training Contest 10 Solution
A - Problem A.Alkane 留坑. B - Problem B. Beads 留坑. C - Problem C. Calculate 留坑. D - Problem D. Permut ...
随机推荐
- GIS-011-Cesium 使用 IIS设置
.terrain Content-Type='application/octet-stream'
- BigDecimal类(精度计算类)的加减乘除
BigDecimal类 对于不需要任何准确计算精度的数字可以直接使用float或double,但是如果需要精确计算的结果,则必须使用BigDecimal类,而且使用BigDecimal类也可以进行大数 ...
- NUC970 U-Boot 使用說明
U-Boot 使用說明U-Boot 是一個主要用於嵌入式系統的開機載入程式, 可以支援多種不同的計算機系統結構, 包括ARM.MIPS.x86與 68K. 這也是一套在GNU通用公共許可證之下發布的自 ...
- Objective-C中的KVC与KVO(上)
本文转载 李朴之先生博客 http://blog.csdn.net/pucker/article/details/7413280 Objective-C中的KVC与KVO是两种比较重要的技术,这里简要 ...
- PyQt4进度条QProgressBar
当我们在处理一个好事较长的任务时,可能就会用到进度条部件.因为使用进度条可以形象告诉用户当前的人物正在进行中.PyQt4工具包提供了水平和垂直两种类型的进度条部件.我们可以设置进度条的最大和最小值,默 ...
- java高级---->Thread之Condition的使用
Condition 将 Object 监视器方法(wait.notify 和 notifyAll)分解成截然不同的对象,以便通过将这些对象与任意 Lock 实现组合使用,为每个对象提供多个等待 set ...
- c# SQL Server数据库操作-数据适配器类:SqlDataAdapter
SqlDataAdapter类主要在MSSQL与DataSet之间执行数据传输工具,本节将介绍如何使用SqlDataAdapter类来填充DataSet和MSSQL执行新增.修改..删除等操作. 功能 ...
- gradle下的第一个SpringMVC应用
新建gradle project 缺少了很多文件夹和文件,我们自己补充,补充完的目录如下: HelloController: package controller; import javax.serv ...
- Python 自学积累(一)
1. 当"print os.path.dirname(__file__)"所在脚本是以完整路径被运行的, 那么将输出该脚本所在的完整路径,比如: python d:/pythonS ...
- CodeForces 651 C Watchmen
C. Watchmen time limit per test 3 seconds memory limit per test 256 megabytes input standard input o ...