Codeforces Round #483 (Div. 2)
题目链接:
https://cn.vjudge.net/contest/229761
A题:
n个数字,两个人轮流去数字,直到剩下最后一个数字为止,第一个人希望剩下的数字最小,第二个人希望数字最大,最终数字是多少?
思路:
贪心,第一个人每次取最大的,第二个人取最小的,最后就是中间值,直接排序即可。
代码:
#include<bits/stdc++.h>
using namespace std;
int a[];
int main()
{
int n;
cin >> n;
for(int i = ; i <= n; i++)cin >> a[i];
sort(a + , a + + n);
cout<<a[(n + ) / ]<<endl;
return ;
}
B题:给出扫雷图,判断是否正确,其中 '.' 表示空的地方 *表示地雷
直接模拟即可,对每个地雷8个方向加1,最后判断一下数字和空格是否都正确
代码:
#include<bits/stdc++.h>
using namespace std;
char a[][];
int Map[][];
int dir[][] = {,,,,-,,,-,,,,-,-,,-,-};
int main()
{
int n, m;
cin >> n >> m;
for(int i = ; i < n; i++)
{
cin >> a[i];
for(int j = ; j < m; j++)
{
if(a[i][j] == '*')
{
for(int k = ; k < ; k++)
{
int x = i + dir[k][];
int y = j + dir[k][];
if(x >= && x < n && y >= && y < m)
Map[x][y]++;
}
}
}
}/*
for(int i = 0; i < n; i++)
{
for(int j = 0; j < m; j++)cout<<Map[i][j]<<" ";
cout<<endl;
}*/
bool flag = ;
for(int i = ; i < n; i++)
{
for(int j = ; j < m; j++)
{
if(a[i][j] != '*')
{
if(a[i][j] == '.' && Map[i][j] != )
flag = ;
if(isdigit(a[i][j]) && Map[i][j] != a[i][j] - '')
flag = ;
}
}
}
if(flag)cout<<"YES\n";
else cout<<"NO\n"; return ;
}
C题:给出p,q,b,询问分数p / q在b进制下是不是循环小数
思路:
先对p和q进行约分,判断是不是循环小数的话,只要q的素因子是b的素因子。
比如在10进制中,如果最简分数p / q不是循环小数,那么q的素因子只能是2和5
所以可以对q和b求出最大公因数g,如果g为1,说明没有相同因子,说明肯定是循环小数
如果g不为1,q一直除以g,不断减小,在重复上述过程,知道q等于1为止,如果不是循环小数,不会出现gcd为1的情况
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b)
{
return b == ? a : gcd(b, a % b);
}
int main()
{
int T;
cin >> T;
while(T--)
{
ll p, q, b;
scanf("%lld%lld%lld", &p, &q, &b);
ll g = gcd(p, q);
p /= g;
q /= g;
bool flag = ;
while(q != )
{
g = gcd(q, b);
if(g == )
{
flag = ;//循环小数
break;
}
while(q % g == )q /= g;//需要不断的把g除掉,不然会超时
}
if(flag)printf("Finite\n");
else printf("Infinite\n");
}
return ;
}
D题:
给出q个询问,每个询问有l到r,求l-r的子序列中最大的f值
思路:做题时没想出,后来找题解发现其实很简单,就是一个规律
对于f(l , r) = f(l, r - 1)^ f(l + 1, r)
根据这个规律,就可以打表出所有的f(l, r)
dp[l][r] = max(f[l][r], f[l][r - 1], f[l +1][r])
注意更新f和dp的时候采用区间DP的写法去更新
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = + ;
int a[maxn], dp[maxn][maxn];
int main()
{
int n, q, l, r;
cin >> n;
for(int i = ; i <= n; i++)scanf("%d", &a[i]);
for(int i = ; i <= n; i++)dp[i][i] = a[i];
for(int len = ; len < n; len++)
{
for(int l = ; l + len <= n; l++)
{
int r = l + len;
dp[l][r] = dp[l][r - ] ^ dp[l + ][r];
}
}
for(int len = ; len < n; len++)
{
for(int l = ; l + len <= n; l++)
{
int r = l + len;
dp[l][r] = max(dp[l][r], max(dp[l][r - ] , dp[l + ][r]));
}
}
cin >> q;
while(q--)
{
scanf("%d%d", &l, &r);
printf("%d\n", dp[l][r]);
}
return ;
}
E留坑待补
Codeforces Round #483 (Div. 2)的更多相关文章
- 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) [Thanks, Botan Investments and Victor Shaburov!]
题目链接:http://codeforces.com/contest/984 A. Game time limit per test:2 seconds memory limit per test:5 ...
- 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. 1
A:首先将p和q约分.容易发现相当于要求存在k满足bk mod q=0,也即b包含q的所有质因子.当然不能直接分解质因数,考虑每次给q除掉gcd(b,q),若能将q除至1则说明合法.但这个辣鸡题卡常, ...
- Codeforces Round #483 (Div. 2)题解
A. Game time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...
- 【递推】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& ...
随机推荐
- 数据结构是哈希表(hashTable)
哈希表也称为散列表,是根据关键字值(key value)而直接进行访问的数据结构.也就是说,它通过把关键字值映射到一个位置来访问记录,以加快查找的速度.这个映射函数称为哈希函数(也称为散列函数),映射 ...
- OpenCV 1 图像分割--分水岭算法代码
// watershed_test20140801.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" // // ch9_watershed ...
- JVM学习--(三)配置参数
JVM配置参数分为三类参数: 1.跟踪参数 2.堆分配参数 3.栈分配参数 这三类参数分别用于跟踪监控JVM状态,分配堆内存以及分配栈内存. 跟踪参数 跟踪参数用于跟踪监控JVM,往往被开发人员用于J ...
- Eclipse 3.5 以后安装插件很慢的解决办法
1 .除非你需要,否则不要选择"联接到所有更新站点" 在安装对话框里有一个小复选框,其标示为"在安装过程中联接到所有更新站点从而找到所需的软件."从表面上看,这 ...
- Event 对象
哪个鼠标按钮被点击? <html> <head> <script type="text/javascript"> function whichB ...
- 讲解Oracle面试过程中常见的二十个问题
1.冷备份和热备份的不同点以及各自的优点 解答:热备份针对归档模式的数据库,在数据库仍旧处于工作状态时进行备份.而冷备份指在数据库关闭后,进行备份,适用于所有模式的数据库.热备份的优点在于当备 ...
- TCP TIME WAIT
根据TCP协议定义的3次握手断开连接规定,发起socket主动关闭的一方 socket将进入TIME_WAIT状态,TIME_WAIT状态将持续2个MSL(Max Segment Lifetime) ...
- 在SQL Server 2008 Management Studio中修改表字段顺序
有时我们可能需要为一个已存在的数据库表添加字段,并且想让这个字段默认排的靠前一些,这时就需要为表字段重新进行排序,默认情况下在Management Studio中调整顺序并保存时会提示"不允 ...
- Mac Launchpad出现两个相同快捷方式的解决办法
进入以下目录 ~/Library/Application Support/Dock 把里面的.db文件删掉,然后注销重新登录即可.
- Android开发阅读文档资源
Android Studio:工具:http://developer.android.com/intl/zh-cn/tools/studio/index.html培训教程:http://develop ...
