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的更多相关文章

  1. 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, ...

  2. 2018 Multi-University Training Contest 2 Solution

    A - Absolute 留坑. B - Counting Permutations 留坑. C - Cover 留坑. D - Game puts("Yes") #include ...

  3. 2018 Multi-University Training Contest 3 Solution

    A - Problem A. Ascending Rating 题意:给出n个数,给出区间长度m.对于每个区间,初始值的max为0,cnt为0.遇到一个a[i] > ans, 更新ans并且cn ...

  4. 2018 Multi-University Training Contest 5 Solution

    A - Always Online Unsolved. B - Beautiful Now Solved. 题意: 给出一个n, k  每次可以将n这个数字上的某两位交换,最多交换k次,求交换后的最大 ...

  5. 2018 Multi-University Training Contest 6 Solution

    A - oval-and-rectangle 题意:给出一个椭圆的a 和 b,在$[0, b]中随机选择c$ 使得四个顶点在椭圆上构成一个矩形,求矩形周长期望 思路:求出每种矩形的周长,除以b(积分) ...

  6. 2018 Multi-University Training Contest 7 Solution

    A - Age of Moyu 题意:给出一张图,从1走到n,如果相邻两次走的边的权值不同,花费+1, 否则花费相同,求最小花费 思路:用set记录有当前点的最小花费有多少种方案到达,然后最短路 #i ...

  7. 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时 ...

  8. 2018 Multi-University Training Contest 9 Solution

    A - Rikka with Nash Equilibrium 题意:构造一个$n * m$的矩阵,使得$[1, n * m]$ 中每个数只出现一次,并且纳什均衡只出现一次. 思路:从大到小的放置,每 ...

  9. 2018 Multi-University Training Contest 10 Solution

    A - Problem A.Alkane 留坑. B - Problem B. Beads 留坑. C - Problem C. Calculate 留坑. D - Problem D. Permut ...

随机推荐

  1. long()

    long() 用于将一个对象转换为长整数 In [35]: long(') # 将纯数字的字符串转换为长整数 Out[35]: 123L In [36]: long(12.3) # 将浮点数转换为长整 ...

  2. 说说M451例程讲解之LED

    /**************************************************************************//** * @file main.c * @ve ...

  3. 【转载】为ASP.NET MVC及WebApi添加路由优先级

    路由方面的: 转载地址:http://www.jb51.net/article/73417.htm Author:lijiao 这是一个对Asp.Net Mvc的一个很小的功能拓展,小项目可能不太需要 ...

  4. springjdbc的批量操作

    这里主要是看的官方文档,如何翻译: NamedParameterJdbcTemplate The NamedParameterJdbcTemplate class adds support for p ...

  5. web图片100%宽度自适应,高度不塌陷

    一般在web端图片100%自适应,在页面加载的时候存在高度塌陷的问题 解决这个问题其实很简单,用padding-top设置百分比值来实现自适应,公式如下 padding-top = (Image He ...

  6. android极光推送

    版权声明:本文为博主原创文章,未经博主允许不得转载. Android开发记录18-集成推送服务的一点说明 关于推送服务,国内有很多选择,笔者也对它们进行了一个详细的对比,一般我们产品选择推送服务主要考 ...

  7. jfinal的controller默认访问的方法是什么

    index()方法: 如: @Controller("/test/exam")public class TestController 如下请求请求:http://localhost ...

  8. mysql如何用sql增加字段和注释?

    alter table warn_user_binding add is_valid varchar(10) default 'true' COMMENT '删除标识:true 有效:false 删除 ...

  9. 基础概念 之 Spark on Yarn

    先抛出问题:Spark on Yarn有cluster和client两种模式,它们有什么区别? 用Jupyter写Spark时,只能使用client模式,为什么? 写一篇文章,搞清楚 Spark on ...

  10. 110道python题+理解(不断更新)

    此篇题目在网上已经广为流传,但好多都不做解释,所以我想着自己一道一道的做一遍,并将相关涉及的做个补充,个人知识毕竟片面,有不足的地方还请大家多多指正 一.请用一行代码实现1-100之和 >> ...