Codeforces Round #483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!]
题目链接:http://codeforces.com/contest/984
Two players play a game.
Initially there are nn integers a1,a2,…,ana1,a2,…,an written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. n−1n−1 turns are made. The first player makes the first move, then players alternate turns.
The first player wants to minimize the last number that would be left on the board, while the second player wants to maximize it.
You want to know what number will be left on the board after n−1n−1 turns if both players make optimal moves.
The first line contains one integer nn (1≤n≤10001≤n≤1000) — the number of numbers on the board.
The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1061≤ai≤106).
Print one number that will be left on the board.
3
2 1 3
2
3
2 2 2
2
In the first sample, the first player erases 33 and the second erases 11. 22 is left on the board.
In the second sample, 22 is left on the board regardless of the actions of the players.
题意:给你n个数,求出排在中间的那个数,签到题。
代码实现如下:
#include <bits/stdc++.h>
using namespace std; int n;
int a[]; int main() {
cin >>n;
for(int i = ; i < n; i++) {
cin >>a[i];
}
sort(a, a + n);
if(n % == ) {
cout <<a[n/] <<endl;
} else {
cout <<a[(n-) / ] <<endl;
}
return ;
}
One day Alex decided to remember childhood when computers were not too powerful and lots of people played only default games. Alex enjoyed playing Minesweeper that time. He imagined that he saved world from bombs planted by terrorists, but he rarely won.
Alex has grown up since then, so he easily wins the most difficult levels. This quickly bored him, and he thought: what if the computer gave him invalid fields in the childhood and Alex could not win because of it?
He needs your help to check it.
A Minesweeper field is a rectangle n×mn×m, where each cell is either empty, or contains a digit from 11 to 88, or a bomb. The field is valid if for each cell:
- if there is a digit kk in the cell, then exactly kk neighboring cells have bombs.
- if the cell is empty, then all neighboring cells have no bombs.
Two cells are neighbors if they have a common side or a corner (i. e. a cell has at most 88 neighboring cells).
The first line contains two integers nn and mm (1≤n,m≤1001≤n,m≤100) — the sizes of the field.
The next nn lines contain the description of the field. Each line contains mm characters, each of them is "." (if this cell is empty), "*" (if there is bomb in this cell), or a digit from 11 to 88, inclusive.
Print "YES", if the field is valid and "NO" otherwise.
You can choose the case (lower or upper) for each letter arbitrarily.
3 3
111
1*1
111
YES
2 4
*.*.
1211
NO
In the second example the answer is "NO" because, if the positions of the bombs are preserved, the first line of the field should be *2*1.
You can read more about Minesweeper in Wikipedia's article.
题意:扫雷游戏,让你判断他给你的图是否合法(.表示周围八格里面没有雷,*表示雷,数字表示周围有几颗雷)。
思路:用一个dfs跑一个标准图出来,然后进行对照即可。
代码实现如下:
#include <bits/stdc++.h>
using namespace std; int n, m;
char mp[][], check[][];
int vis[][]; void dfs(int x, int y) {
vis[x][y] = ;
int cnt = ;
for(int i = -; i < ; i++) {
for(int j = -; j < ; j++) {
if(i == && j == ) continue;
int nx = x + i, ny = y + j;
if(nx >= && nx < n && ny >= && ny < m) {
if(check[nx][ny] == '*') cnt++;
if(vis[nx][ny] == ) {
dfs(nx, ny);
}
}
}
}
if(cnt && check[x][y] == '.') {
check[x][y] = cnt + '';
}
} int main() {
cin >>n >>m;
for(int i = ; i < n; i++) {
cin >>mp[i];
}
for(int i = ; i < n; i++) {
for(int j = ; j < m; j++) {
if(mp[i][j] == '*') {
check[i][j] = '*';
} else {
check[i][j] = '.';
}
}
}
dfs(, );
int flag = ;
for(int i = ; i < n; i++) {
for(int j = ; j < m; j++) {
if(mp[i][j] != check[i][j]) {
flag = ;
break;
}
}
}
if(flag) cout <<"YES" <<endl;
else cout <<"NO" <<endl;
return ;
}
You are given several queries. Each query consists of three integers pp, qq and bb. You need to answer whether the result of p/qp/q in notation with base bb is a finite fraction.
A fraction in notation with base bb is finite if it contains finite number of numerals after the decimal point. It is also possible that a fraction has zero numerals after the decimal point.
The first line contains a single integer nn (1≤n≤1051≤n≤105) — the number of queries.
Next nn lines contain queries, one per line. Each line contains three integers pp, qq, and bb (0≤p≤10180≤p≤1018, 1≤q≤10181≤q≤1018, 2≤b≤10182≤b≤1018). All numbers are given in notation with base 1010.
For each question, in a separate line, print Finite if the fraction is finite and Infinite otherwise.
2
6 12 10
4 3 10
Finite
Infinite
4
1 1 2
9 36 2
4 12 3
3 5 4
Finite
Finite
Finite
Infinite
题意:给你一个p,q,b,问p/q在b进制下是否为有限小数。
思路:数论题,方法为判断b的x次方是否能整除q。一开始我用的是唯一分解定理,但是一直T,从T10->WA7->T11,然后本以为接近正理了,然后就没有然后了,其实这题可以用gcd来将q进行消去因子,最后判断q是否等于1。注意小trick,不然还是会T。
代码实现如下:
#include <bits/stdc++.h>
using namespace std; typedef long long ll;
int n;
ll p, q, b; ll gcd(ll a, ll b) {
return (b == ) ? a : gcd(b, a % b);
} int main() {
ios::sync_with_stdio(false);
cin.tie();
cin >>n;
while(n--) {
cin >>p >>q >>b;
ll g = gcd(p, q);
p = p / g;
q = q / g;
while(g = gcd(q, b), g != ) {
while(q % g == ) q /= g;
}
if(q == ) cout <<"Finite" <<endl;
else cout <<"Infinite" <<endl;
}
return ;
}
For an array bb of length mm we define the function ff as
where ⊕⊕ is bitwise exclusive OR.
For example, f(1,2,4,8)=f(1⊕2,2⊕4,4⊕8)=f(3,6,12)=f(3⊕6,6⊕12)=f(5,10)=f(5⊕10)=f(15)=15f(1,2,4,8)=f(1⊕2,2⊕4,4⊕8)=f(3,6,12)=f(3⊕6,6⊕12)=f(5,10)=f(5⊕10)=f(15)=15
You are given an array aa and a few queries. Each query is represented as two integers ll and rr. The answer is the maximum value of ff on all continuous subsegments of the array al,al+1,…,aral,al+1,…,ar.
The first line contains a single integer nn (1≤n≤50001≤n≤5000) — the length of aa.
The second line contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤230−10≤ai≤230−1) — the elements of the array.
The third line contains a single integer qq (1≤q≤1000001≤q≤100000) — the number of queries.
Each of the next qq lines contains a query represented as two integers ll, rr (1≤l≤r≤n1≤l≤r≤n).
Print qq lines — the answers for the queries.
3
8 4 1
2
2 3
1 2
5
12
6
1 2 4 8 16 32
4
1 6
2 5
3 4
1 2
60
30
12
3
In first sample in both queries the maximum value of the function is reached on the subsegment that is equal to the whole segment.
In second sample, optimal segment for first query are [3,6][3,6], for second query — [2,5][2,5], for third — [3,4][3,4], for fourth — [1,2][1,2].
题意:给你一个序列,然后按照他所给的递推式求出所问区间内f的最大值。
思路:仔细研究一下这个递推式会发现本题的方法为区间dp。由于询问次数太大,因而我们先进行预处理,然后就能在O(1)的复杂度内进行询问。
代码实现如下:
#include <bits/stdc++.h>
using namespace std; typedef long long ll;
const int maxn = 5e3 + ;
int n, q, l, r;
ll a[maxn], ans[maxn][maxn], dp[maxn][maxn]; int main() {
ios::sync_with_stdio(false);
cin.tie();
cin >>n;
for(int i = ; i <= n; i++) {
cin >>a[i];
dp[i][i] = a[i];
ans[i][i] = a[i];
}
for(int i = ; i <= n; i++) {
for(int j = ; j + i <= n; j++) {
ans[j][j+i] = ans[j][j+i-] ^ ans[j+][i+j];
dp[j][j+i] = max(ans[j][j+i], max(dp[j][j+i-], dp[j+][i+j]));
}
}
cin >>q;
while(q--) {
cin >>l >>r;
cout <<dp[l][r] <<endl;
}
return ;
}
Codeforces Round #483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!]的更多相关文章
- 【递推】Codeforces Round #483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!] D. XOR-pyramid
题意:定义,对于a数组的一个子区间[l,r],f[l,r]定义为对该子区间执行f操作的值.显然,有f[l,r]=f[l,r-1] xor f[l+1,r].又定义ans[l,r]为满足l<=i& ...
- 【数论】Codeforces Round #483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!] C. Finite or not?
题意:给你一个分数,问你在b进制下能否化成有限小数. 条件:p/q假如已是既约分数,那么如果q的质因数分解集合是b的子集,就可以化成有限小数,否则不能. 参见代码:反复从q中除去b和q的公因子部分,并 ...
- Codeforces Round #483 (Div. 2) B题
B. Minesweeper time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #483 (Div. 2)C题
C. Finite or not? time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces Round #483 (Div. 2) B. Minesweeper
题目地址:http://codeforces.com/contest/984/problem/B 题目大意:扫雷游戏,给你一个n*m的地图,如果有炸弹,旁边的八个位置都会+1,问这幅图是不是正确的. ...
- Codeforces Round #483 (Div. 2) C. Finite or not?
C. Finite or not? time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces Round #483 (Div. 2) D. XOR-pyramid
D. XOR-pyramid time limit per test 2 seconds memory limit per test 512 megabytes input standard inpu ...
- Codeforces Round #483 (Div. 2)
题目链接: https://cn.vjudge.net/contest/229761 A题: n个数字,两个人轮流去数字,直到剩下最后一个数字为止,第一个人希望剩下的数字最小,第二个人希望数字最大,最 ...
- Codeforces Round #483 Div. 1
A:首先将p和q约分.容易发现相当于要求存在k满足bk mod q=0,也即b包含q的所有质因子.当然不能直接分解质因数,考虑每次给q除掉gcd(b,q),若能将q除至1则说明合法.但这个辣鸡题卡常, ...
随机推荐
- iOS- 无处不在,详解iOS集成第三方登录(SSO授权登录<无需密码>)
1.前言 不多说,第三登录无处不在!必备技能,今天以新浪微博为例. 这是上次写的iOS第三方社交分享:http://www.cnblogs.com/qingche/p/3727559.html 可 ...
- C运行时库
原文地址:http://blog.csdn.net/wqvbjhc/article/details/6612099 在开发window程序是经常会遇到编译好好的程序拿到另一台机器上面无法运行的情况,这 ...
- perf record -c
如果perf record -c -c后面接的是sample_period,也就是说你让这个事件没 我的loop进程一直在执行,我的CPU的频率是2.6G hz,也就是说每一秒会有2,600,000, ...
- 如何取得dbgrid中未保存(post)的值(50分)
比如说处在编辑状态时,想取得当前记录值 Dataset.fields[0].Value 就是当前值:Dataset.fields[0].OldValue 就是原始值. 呵呵,我指得是在编辑时,就是按键 ...
- 能选择日期范围js控件
html页面中使用日期控件是常有的事,好控件能使用开发变的快捷,下面是在开发过程中发现的几款日期控件,比较不错,收藏 1.基于bootstrap的jQuery日期范围选择插件 2.jQuery多功能日 ...
- BZOJ 2208 连通数(强连通分量)
先缩点,对于缩完点后的DAG,可以直接在每个scc dfs一次就可以求出终点是这个scc的点的点对个数. # include <cstdio> # include <cstring& ...
- 在git 服务器挂载、创建新的项目、克隆新的项目
流程,服务器创建项目名-->客户端克隆-->客户端提交并且推送-->完成 详细步骤 1.在git服务器路径文件夹下创建空文件夹,名字为新的项目名,如在 F:\git ...
- BZOJ4004:[JLOI2015]装备购买——题解
https://www.lydsy.com/JudgeOnline/problem.php?id=4004 https://www.luogu.org/problemnew/show/P3265 脸哥 ...
- UOJ228:基础数据结构练习题——题解
http://uoj.ac/problem/228 参考:https://www.cnblogs.com/ljh2000-jump/p/6357583.html 考虑当整个区间的最大值开方==最小值开 ...
- 从零开始学Linux系统(一)之引导流程解析
Linux系统:分时多用户多任务的操作系统: Linux系统引导流程: inittab配置文件中: 定义了linux系统的运行的7个级别:从0~6 0.6:分别代表关机和重启,不建议设置为默认的运行级 ...