2018 Multi-University Training Contest 4 Solution
A - Problem A. Integers Exhibition
留坑。
B - Problem B. Harvest of Apples
题意:计算$\sum_{i = 0}^{i = m}C(n, i)$
思路:由$sum_{i = 0}^{i = m}C(n,i)$可以得到$sum_{i = 0}^{i = m + 1}C(n,i)$以及$sum_{i = 0}^{i = m}C(n + 1,i)$然后用莫对算法求解
#include<bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 1e9 + ;
const int maxn = 1e5 + ; int unit;
ll inv[maxn];
ll invfac[maxn];
ll fac[maxn];
ll ans[maxn];
int n, m; struct node{
int l, r, id;
inline node(){}
inline node(int l, int r, int id) :l(l), r(r), id(id){}
inline bool operator < (const node &b) const
{
if(l / unit != b.l / unit) return l / unit < b.l / unit;
else return r < b.r;
}
}arr[maxn]; inline void Init()
{
fac[] = invfac[] = ;
fac[] = inv[] = invfac[] = ;
for(int i = ; i < maxn; ++i)
{
fac[i] = fac[i - ] * i % MOD;
inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
invfac[i] = invfac[i - ] * inv[i] % MOD;
}
} inline ll cal(int a, int b)
{
ll res = fac[a] * invfac[b] % MOD * invfac[a - b] % MOD;
return res;
} inline void work()
{
ll tmp = ;
for(int i = ; i <= arr[].r; ++i)
{
tmp = (tmp + cal(arr[].l, i)) % MOD;
}
ans[arr[].id] = tmp;
int L = arr[].l, R = arr[].r;
for(int i = ; i <= n; ++i)
{
while(L < arr[i].l)
{
tmp = (tmp * % MOD- cal(L++, R) + MOD) % MOD;
}
while(L > arr[i].l)
{
tmp = (tmp + cal(--L, R) + MOD) % MOD * inv[] % MOD;
}
while(R < arr[i].r)
{
tmp = (tmp + cal(L, ++R)) % MOD;
}
while(R > arr[i].r)
{
tmp = (tmp - cal(L, R--) + MOD) % MOD;
}
ans[arr[i].id] = tmp;
}
} int main()
{
Init();
scanf("%d", &n);
for(int i = ; i <= n; ++i)
{
scanf("%d %d", &arr[i].l, &arr[i].r);
arr[i].id = i;
}
unit = (int)sqrt(n);
sort(arr + , arr + + n);
work();
for(int i = ; i <= n; ++i)
{
printf("%lld\n", ans[i]);
}
return ;
}
C - Problem C. Problems on a Tree
留坑。
D - Problem D. Nothing is Impossible
题意:给出n道题目,每道题目有$a_i种正确选择,b_i种错误选择$ 一共有m个人,所有人都要选择一个题目集合去做,相当于去试答案,问最多能试出多少道题目答案
思路:排序,前缀积。
#include <bits/stdc++.h>
using namespace std; #define N 110
#define ll long long struct node
{
int a, b, sum;
inline void scan()
{
scanf("%d%d", &a, &b);
sum = a + b;
}
inline bool operator < (const node &r) const
{
return sum < r.sum;
}
}arr[N]; int t, n, m;
ll sum; int main()
{
scanf("%d", &t);
while (t--)
{
scanf("%d%d", &n, &m);
for (int i = ; i <= n; ++i) arr[i].scan();
sort(arr + , arr + + n);
int ans = ; sum = ;
for (int i = ; i <= n; ++i)
{
sum *= arr[i].sum;
if (sum > m) break;
ans = i;
}
printf("%d\n", ans);
}
return ;
}
E - Problem E. Matrix from Arrays
题意:给出一种构造二维数组的构造方式,然后给出一个左上角,一个右下角,求这个矩形内的数和
思路:打表找规律发现,大矩阵是由若干个$2L \cdot 2L$个小矩阵构成的,那么把给出的矩阵分成四块,整块整块的处理,边边角角的处理
#include<bits/stdc++.h> using namespace std; #define N 110 typedef long long ll; int n;
int x[], y[];
ll arr[N];
ll G[N][N]; inline ll cal(int x,int y)
{
if(x < || y < ) return 0ll;
ll res = G[n - ][n - ] * (x / n) * (y / n) + G[n - ][y % n] * (x / n) + G[x % n][n - ] * (y / n) + G[x % n][y % n];
return res;
} int main()
{
int t;
scanf("%d", &t);
while(t--)
{
scanf("%d", &n);
for(int i = ; i < n; ++i)
{
scanf("%lld", arr + i);
}
for(int i = , cnt = ; i < (n << ); ++i)
{
for(int j = ; j <= i; ++j)
{
G[j][i - j] = arr[cnt];
cnt = (cnt + ) % n;
}
}
n <<= ;
for(int i = ; i < n; ++i)
{
for(int j = ; j < n; ++j)
{
G[i][j] += (i ? G[i - ][j] : );
G[i][j] += (j ? G[i][j - ] : );
G[i][j] -= ((i && j) ? G[i - ][j - ] : );
}
}
int q;
scanf("%d", &q);
while(q--)
{
scanf("%d %d %d %d", &x[], &y[], &x[], &y[]);
ll ans = cal(x[], y[]) - cal(x[] - , y[]) - cal(x[], y[] - ) + cal(x[] - , y[] - );
printf("%lld\n", ans);
}
}
return ;
}
#include <bits/stdc++.h>
using namespace std; #define N 1100
#define ll long long int t, n, q, x[], y[];
ll arr[N];
ll G[N][N]; int main()
{
scanf("%d", &t);
while (t--)
{
scanf("%d", &n);
for (int i = ; i <= n; ++i) scanf("%lld", arr + i);
memset(G, , sizeof G);
for (int i = , cnt = ; i <= (n << ); ++i)
{
for (int j = ; j <= i; ++j)
{
G[j][i - j] = arr[cnt + ];
cnt = (cnt + ) % n;
}
}
n <<= ;
ll base = ;
for (int i = ; i < n; ++i) for (int j = ; j < n; ++j) base += G[i][j];
scanf("%d", &q);
while (q--)
{
scanf("%d%d%d%d", &x[], &y[], &x[], &y[]);
ll ans = , tmp;
//compute Big
ll xl = (x[] - x[] + ) / n, yl = (y[] - y[] + ) / n; ans += (base * xl * yl);
//compute lower_left corner
tmp = ;
for (int i = x[] + xl * n; i <= x[]; ++i)
{
for (int j = y[], cnt = ; cnt <= n; ++cnt, ++j)
tmp += G[i % n][j % n];
}
//compute upper_right corner
ans += tmp * yl; tmp = ;
for (int i = x[], cnt = ; cnt <= n; ++cnt, ++i)
{
for (int j = y[] + yl * n; j <= y[]; ++j)
tmp += G[i % n][j % n];
}
//compute lower_right corner
ans += tmp * xl; tmp = ;
for (int i = x[] + xl * n; i <= x[]; ++i)
{
for (int j = y[] + yl * n; j <= y[]; ++j)
ans += G[i % n][j % n];
}
printf("%lld\n", ans);
}
}
return ;
}
F - Problem F. Travel Through Time
留坑。
G - Problem G. Depth-First Search
留坑。
H - Problem H. Eat Cards, Have Fun
留坑。
I - Problem I. Delightful Formulas
留坑。
J - Problem J. Let Sudoku Rotate
题意:给出一个16 * 16 的数独, 有一些4 * 4 的矩阵被逆时针旋转过,然后求恢复最少需要旋转多少次
思路:爆搜,两条剪枝,一个是判断是否有冲突,一个是判断当前步数是否比已有答案大
#include<bits/stdc++.h> using namespace std; const int maxn = 1e2 + ; int ans;
bool vis[];
char s[];
int G[maxn][maxn]; inline bool judge(int x,int y)
{
for(int i = x * - ; i <= x * ; ++i)
{
memset(vis, false, sizeof vis);
for(int j = ; j <= y * ; ++j)
{
if(vis[G[i][j]]) return false;
vis[G[i][j]] = true;
}
}
for(int i = y * - ; i <= y * ; ++i)
{
memset(vis, false, sizeof vis);
for(int j = ; j <= x * ; ++j)
{
if(vis[G[j][i]]) return false;
vis[G[j][i]] = true;
}
}
return true;
} inline void fun(int x, int y)
{
int tmp[][];
for(int i = ; i <= ; ++i)
{
for(int j = ; j <= ; ++j)
{
tmp[j][ - i + ] = G[(x - ) * + i][(y - ) * + j];
}
}
for(int i = ; i <= ; ++i)
{
for(int j = ; j <= ; ++j)
{
G[(x - ) * + i][(y - ) * + j] = tmp[i][j];
}
}
}
inline void DFS(int x,int y,int res)
{
if(res >= ans) return ;
if(y > )
{
DFS(x + , , res);
return ;
}
if(x == )
{
ans = min(ans, res);
return ;
}
for(int i = ; i < ; ++i)
{
if(i)
{
fun(x, y);
/* if(x == 3 && y == 1 && i == 1)
{
for(int i = x * 4 - 3; i <= x * 4; ++i)
{
for(int j = y * 4 - 3; j <= y * 4; ++j)
{
printf("%d%c", G[i][j], " \n"[j == y * 4]);
}
}
}*/
}
if(judge(x, y))
{
DFS(x, y + , res + i);
}
}
fun(x, y);
} int main()
{
int t;
scanf("%d", &t);
while(t--)
{
ans = << ;
for(int i = ; i <= ; ++i)
{
scanf("%s", s + );
for(int j = ; j <= ; ++j)
{
if(s[j] >= '' && s[j] <= '')
{
G[i][j] = s[j] - '';
}
else if(s[j] >= 'A' && s[j] <= 'F')
{
G[i][j] = (s[j] - 'A') + ;
}
}
}
// fun(1, 1);
DFS(, , );
printf("%d\n", ans);
}
return ;
}
K - Problem K. Expression in Memories
按题意模拟即可
#include <bits/stdc++.h>
using namespace std; #define N 100010 int t;
char s[N]; int main()
{
scanf("%d", &t);
while (t--)
{
scanf("%s", s);
bool flag = true;
int len = strlen(s);
for(int i = ; i < len; ++i)
{
if(s[i] == '*' || s[i] == '+')
{
if(i == || i == len - )
{
flag = false;
break;
}
else if(s[i + ] == '*' || s[i + ] == '+')
{
flag = false;
break;
}
}
else if(s[i] == '')
{
if(i == || s[i - ] == '*' || s[i - ] == '+')
{
if(i + < len && s[i + ] >= '' && s[i + ] <= '')
{
flag = false;
break;
}
else if(s[i + ] == '?') s[i + ] = '+';
}
}
else if(s[i] == '?')
{
s[i] = '';
}
}
if(flag)
{
printf("%s\n", s);
}
else
{
printf("IMPOSSIBLE\n");
}
}
return ;
}
L - Problem L. Graph Theory Homework
水。
#include <bits/stdc++.h>
using namespace std; #define N 100010 int t, n;
int arr[N]; int main()
{
scanf("%d", &t);
while (t--)
{
scanf("%d", &n);
for (int i = ; i <= n; ++i) scanf("%d", arr + i);
int ans = (int)floor(sqrt(abs(arr[] - arr[n])));
printf("%d\n", ans);
}
return ;
}
2018 Multi-University Training Contest 4 Solution的更多相关文章
- 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, ...
- 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 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 ...
随机推荐
- Ehcache整合spring
下面介绍一下简单使用的配置过程:ehcache.jar及spring相关jar就不说了,加到项目中就是了. 简单的使用真的很简单.但只能做为入门级了. 1.ehcache.xml,可放classpat ...
- HTTP 代理
HTTP 代理: (1) 如果我们一直用同一个IP去爬取同一个网站上的网页,久了之后可能会被该网站服务器屏蔽,因此我们可以使用代理IP来爬取,代理实际上指的就是代理服务器(2) 当我们使用代理IP爬取 ...
- UIGestureRecognizer学习笔记2
The concrete subclasses of UIGestureRecognizer are the following: UITapGestureRecognizer UIPinchGest ...
- 上传图片Security Error
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAjIAAACXCAIAAACA4CZ6AAAgAElEQVR4nOy96Xcd13UnugFSUrJer/ ...
- 什么是SQL注入式攻击和如何防范?
什么是SQL注入式攻击? 所谓SQL注入式攻击,就是攻击者把SQL命令插入到Web表单的输入域或页面请求的查询字符串,欺骗服务器执行恶意的SQL命令.在某些表单中,用户输入的内容直接用来构造(或者影响 ...
- Delphi的保存文件对话框-TsaveDialog
TsaveDialog继承于TOpenDialog,只介绍以下几个内容: 1.TsaveDialog如何设定为保存的默认路径是当前程序所在的文件夹: 默认目录是当前程序所在目录应设置属性Initial ...
- 【Android M】获取屏幕锁定的相关信息:“无”,“滑动”,“PIN码”,"图案","密码"
ENV: Android M 6.0.1 import android.os.UserHandle; import com.android.internal.widget.LockPa ...
- 自行颁发不受浏览器信任的SSL证书
ssh登陆到服务器上,终端输入以下命令,使用openssl生成RSA密钥及证书. # 生成一个RSA密钥 $ openssl genrsa -des3 -out 33iq.key 1024 # 拷贝一 ...
- 超级小的web手势库AlloyFinger
针对多点触控设备编程的Web手势组件,快速帮助你的web程序增加手势支持,也不用再担心click 300ms的延迟了.拥有两个版本,无依赖的独立版和react版本.除了Dom对象,也可监听Canvas ...
- Web界面的服务器监测工具(转载)
企业服务器对于企业业务持续性意义重大,系统管理员需要密切关注企业服务器以确保一切正常运行.当发现问题的时候,他们需要知道问题开始出现时的状况,因此调查可以重点放在问题出现的时候,这就意味着定期记录信息 ...