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 ...
随机推荐
- django 错误分类及解决办法汇总
问题1:启动服务器后浏览器无法访问http://localhost:8000,访问被拒绝
- php学习三:函数
1. php中的函数和js中的区别 在php中,函数的形参可以给一个默认值,若有实参的传递则函数使用传递过来的参数,没有的话显示默认值 代码如下: function showSelf($name=& ...
- Spring学习笔记--在SpEL中筛选集合
要用到Spring的util(包括util:list等),xml文件中的beans中需要添加一些有关util的信息: <?xml version="1.0" encoding ...
- Sencha Cmd创建Ext JS示例项目
Sencha提供了免费的Cmd工具,可以用来创建Ext JS项目并提供了一些便利的功能. Sencha也在官方文档中提供了一个示例来演示如何创建一个Sample Login App. 本文就介绍一下这 ...
- 谷歌Volley网络框架讲解——网络枢纽
研究了这么久的Volley,愈来愈发现这个框架的精美和人性化.比起民间一些框架强很多,一开始总是盲人摸象找不到头绪,现在终于有些明朗了.Volley其实就是一个请求队列的代理类,我们看下UML. 这就 ...
- HTML - 分页效果布局
<p class="jcFY"> 显示 <select name="" id=""> <option valu ...
- BOM history对象
history对象的三个可用方法和一个属性 back();后退 forward();前进 go(n);跳到第几个页面,负数为后退,正数为前进 length属性,获取缓存的页面的数量 安全性考虑,his ...
- min-height的兼容性问题
1.经测试 IE+和其它主流浏览器均支持min-height属性,已经满足目前的需求. 2.当height和min-height同时设置时,浏览器自动选择数值更大的一个(测试IE7+及其他主流浏览器) ...
- sencha touch 入门系列 (九)sencha touch 视图组件简介
对于一个普通用户来说,你的项目就是一组简单的视图集合,用户直接通过跟视图进行交互来操作你的应用,对于一个开发人员来说,视图是一个项目的入口,虽然大部分时候最有价值的部分是在model层和control ...
- LINUX IPTABLES 防火墙配置
0.iptables(ACL)的匹配原则: 与cisco等一致,从上到下依次匹配. 1.iptables的基本用法:. (1)命令格式 iptables [–ttable] command [mat ...