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 ...
随机推荐
- Android中Invalidate与postInvalidate的区别<转>
http://www.cnblogs.com/it-tomorrow/archive/2012/11/08/2760146.html 示例:http://rayleung.iteye.com/blog ...
- 用示例详解php连接数据库操作
首先数据库mydb有三个表: 1 info表 2 users表 3 sname表 首先先做一个登录主页面 login_1.php <!DOCTYPE html PUBLIC "- ...
- Suricata开源IDS安装与配置
开源IDS Suricata安装 Linux下的依赖问题的解决 在Debian,Ubuntu或者Linux Mint系列 $ sudo apt-get install wget build-essen ...
- Weinre 远程调试移动端手机web页面
调试场景 1.调试页面在手机上.2.调试工具在PC的chrome3.手机跟pc要在同一个网络环境下,也就是都使用一个wifi 一.安装 Weinre 1.Weinre是基于nodejs实现的,所以使用 ...
- {Repeater控件} Repeater控件的用法流程及实例
一.Repeater控件的用法流程及实例: 1.首先建立一个网站,新建一个网页index.aspx. 2.添加或者建立APP_Data数据文件,然后将用到的数据库文件放到APP_Data文件夹中. 3 ...
- docker swarm+register-web+shipyard搭建
1.swarm安装 swarm安装有很多种服务注册的方式,token.etcd.zookeeper,本文主要以swarm默认的token方式进行安装.因为最新的docker已经集成了swarm,所以从 ...
- 40个DBA日常维护的SQL脚本
1.查询碎片程度高的表 条件为什么block>100,因为一些很小的表,只有几行数据实际大小很小,但是block一次性分配就是5个(11g开始默认一次性分配1M的block大小了,见create ...
- 转!!spring @component 详解 默认初始化bean的名字 VNumberTask类 就是 VNumberTask
参考链接:信息来源 今天碰到一个问题,写了一个@Service的bean,类名大致为:CUser xml配置: <context:component-scan base-package=&quo ...
- D. Little Artem and Dance---cf669D(模拟)
题目链接:http://codeforces.com/problemset/problem/669/D 给你n个数,一开始是1 2 3 4 5 6 ... n 这样的 现在有两个操作,第一个操作是所有 ...
- 拨开障目的叶,一览CMDB庐山真面目
人们往往用"一叶障目,不见泰山"来形容一个人被局部现象所迷惑,看不到事物发展的整体脉络,从而做出一些不是十分正确的决策.小编觉得对于运维何尝不是这样呢. 大多数企业资产配置维护的现 ...