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则说明合法.但这个辣鸡题卡常, ...
 
随机推荐
- 基于3D卷积神经网络的人体行为理解(论文笔记)(转)
			
基于3D卷积神经网络的人体行为理解(论文笔记) zouxy09@qq.com http://blog.csdn.net/zouxy09 最近看Deep Learning的论文,看到这篇论文:3D Co ...
 - 【Redis】- 安装为windows服务
			
1.安装redis服务 echo install redis-server redis-server.exe --service-install redis.windows.conf --loglev ...
 - WebKit 源码分析 -- loader
			
原文地址: http://peirenlei.iteye.com/blog/1718569 摘要:本文介绍 WebCore 中 Loader 模块是如何加载资源的,分主资源和派生资源分析 loader ...
 - dwarf是怎样处理的栈帧?
			
dwarf是如何处理的栈帧呢? 首先看下非dwarf的情况是如何处理栈帧的: 1 3623804982590 0x3e90 [0xb0]: PERF_RECORD_SAMPLE(IP, 0x1): 1 ...
 - 单点登录Windows实现
			
Windows实现步骤: server.xml修改方式 hosts修改方式 CAS客户端配置 CAS配置filter.txt内容如下: <!-- ======================== ...
 - 【hdu4734】F(x)  数位dp
			
题目描述 对于一个非负整数 $x=\overline{a_na_{n-1}...a_2a_1}$ ,设 $F(x)=a_n·2^{n-1}+a_{n-1}·2^{n-2}+...+a_2·2^1+ ...
 - CF484E Sign on Fence && [国家集训队]middle
			
CF484E Sign on Fence #include<bits/stdc++.h> #define RG register #define IL inline #define _ 1 ...
 - [清华集训2017]无限之环(infinityloop)
			
description 题面 solution 一开始的思路是插头\(DP\),然而复杂度太高 考虑将网格图黑白染色后跑费用流 流量为接口数,费用为操作次数 把一个方格拆成五个点,如何连边请自行脑补 ...
 - BZOJ1458 士兵占领  【带上下界网络流】
			
题目链接 BZOJ1458 题解 对行列分别建边,拆点,设置流量下限 然后\(S\)向行连边\(inf\),列向\(T\)连边\(inf\),行列之间如果没有障碍,就连边\(1\) 然后跑最小可行流即 ...
 - CodeForces.71A Way Too Long Words (水模拟)
			
CodeForces71A. Way Too Long Words (水模拟) 题意分析 题怎么说你怎么做 没有坑点 代码总览 #include <iostream> #include & ...