题目链接:http://codeforces.com/contest/984

A. Game
time limit per test:2 seconds
memory limit per test:512 megabytes
input:standard input
output:standard output

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.

Input

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

Output

Print one number that will be left on the board.

Examples
Input

Copy
3
2 1 3
Output

Copy
2
Input

Copy
3
2 2 2
Output

Copy
2
Note

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 ;
}
B. Minesweeper
time limit per test:2 seconds
memory limit per test:512 megabytes
input:standard input
output:standard output

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

Input

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.

Output

Print "YES", if the field is valid and "NO" otherwise.

You can choose the case (lower or upper) for each letter arbitrarily.

Examples
Input

Copy
3 3
111
1*1
111
Output

Copy
YES
Input

Copy
2 4
*.*.
1211
Output

Copy
NO
Note

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 ;
}
C. Finite or not?
time limit per test:2 seconds
memory limit per test:512 megabytes
input:standard input
output:standard output

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.

Input

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.

Output

For each question, in a separate line, print Finite if the fraction is finite and Infinite otherwise.

Examples
Input

Copy
2
6 12 10
4 3 10
Output

Copy
Finite
Infinite
Input

Copy
4
1 1 2
9 36 2
4 12 3
3 5 4
Output

Copy
Finite
Finite
Finite
Infinite
Note

题意:给你一个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 ;
}
D. XOR-pyramid
time limit per test:2 seconds
memory limit per test:512 megabytes
input:standard input
output:standard output

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.

Input

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

Output

Print qq lines — the answers for the queries.

Examples
Input

Copy
3
8 4 1
2
2 3
1 2
Output

Copy
5
12
Input

Copy
6
1 2 4 8 16 32
4
1 6
2 5
3 4
1 2
Output

Copy
60
30
12
3
Note

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

  1. 【递推】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& ...

  2. 【数论】Codeforces Round #483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!] C. Finite or not?

    题意:给你一个分数,问你在b进制下能否化成有限小数. 条件:p/q假如已是既约分数,那么如果q的质因数分解集合是b的子集,就可以化成有限小数,否则不能. 参见代码:反复从q中除去b和q的公因子部分,并 ...

  3. Codeforces Round #483 (Div. 2) B题

    B. Minesweeper time limit per test 1 second memory limit per test 256 megabytes input standard input ...

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

  5. Codeforces Round #483 (Div. 2) B. Minesweeper

    题目地址:http://codeforces.com/contest/984/problem/B 题目大意:扫雷游戏,给你一个n*m的地图,如果有炸弹,旁边的八个位置都会+1,问这幅图是不是正确的. ...

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

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

  8. Codeforces Round #483 (Div. 2)

    题目链接: https://cn.vjudge.net/contest/229761 A题: n个数字,两个人轮流去数字,直到剩下最后一个数字为止,第一个人希望剩下的数字最小,第二个人希望数字最大,最 ...

  9. Codeforces Round #483 Div. 1

    A:首先将p和q约分.容易发现相当于要求存在k满足bk mod q=0,也即b包含q的所有质因子.当然不能直接分解质因数,考虑每次给q除掉gcd(b,q),若能将q除至1则说明合法.但这个辣鸡题卡常, ...

随机推荐

  1. YaoLingJump开发者日志(五)V1.0版本完成

    跳跃吧瑶玲下载连接 官网下载 百度网盘下载 提取码:apx9 介绍   总算完成V1.0版本了,下面来简单地介绍一下吧!   打开游戏,最开始会进入到"主界面".   右上角的按钮 ...

  2. 重新看《JavaScript高级程序设计》

    几点心得: 1)数据是基础,一共有3种基础数据:null.undefined.和object:遵循从无到有从简单到复杂的演变过程 2)衍生数据:衍生数据是指操作符合语句,这些是基础数据产生导致的必然结 ...

  3. PowerMock用法[转]

    转:http://agiledon.github.io/blog/2013/11/21/play-trick-with-powermock/ 当我们面对一个遗留系统时,常见的问题是没有测试.正如Mic ...

  4. django使用ajax提交表单数据报403错解决方法

    只需要在.ajaxSetup方法中设置csrfmiddlewaretoken即可 $.ajaxSetup({ data: {csrfmiddlewaretoken: '{{ csrf_token }} ...

  5. 解决XAMPP中,MYSQL因修改my.ini后,无法启动的问题

    论这世上谁最娇贵,不是每年只开七天的睡火莲,也不是瑞典的维多利亚公主,更不是一到冬天就自动关机的iPhone 6s, 这世上最娇贵的,非XAMPP中的mysql莫属,记得儿时的我,年少轻狂,当时因为m ...

  6. lucene 学习之编码篇

    本文环境:lucene5.2     JDK1.7   IKAnalyzer 引入lucene相关包 <!-- lucene核心包 --> <dependency> <g ...

  7. [剑指Offer] 59.按之字形顺序打印二叉树

    题目描述 请实现一个函数按照之字形打印二叉树,即第一行按照从左到右的顺序打印,第二层按照从右至左的顺序打印,第三行按照从左到右的顺序打印,其他行以此类推. [思路]先按层次遍历存入,通过设立标志位,将 ...

  8. sql 插入列放第一列

    如果是SQLSERVER 的话就这样:select * from dbo.syscolumns where id=OBJECT_ID(N'你的表名') 然后COLID这列就是列的顺序 修改这个字段就行 ...

  9. css的存在形式及优先级

    1. 查看源代码---在谷歌浏览器中右击-->点检查 2. CSS中style优先级,标签上的style优先,其它按照编写顺序越更新越优先,后面的会把前面的覆盖掉. 3. 如果想在其它的html ...

  10. bzoj3110: [Zjoi2013]K大数查询 【树套树,标记永久化】

    //========================== 蒟蒻Macaulish:http://www.cnblogs.com/Macaulish/  转载要声明! //=============== ...