题目链接:

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

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

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

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

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

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

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

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

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

  7. Codeforces Round #483 Div. 1

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

  8. Codeforces Round #483 (Div. 2)题解

    A. Game time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...

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

随机推荐

  1. Java进阶(十八)Java实现定时器(Timer)

    Java实现定时器(Timer) 绪 在应用开发中,经常需要一些周期性的操作,比如每5分钟执行某一操作等.对于这样的操作最方便.高效的实现方式就是使用java.util.Timer工具类.java.u ...

  2. Java开发机器上的配置及zookeeper配置

    Java开发机器上的配置及zookeeper配置 /etc/profile 文件的后面加入下面的内容: # jdk, zookeeper, kafka, ant, maven export APACH ...

  3. "《算法导论》之‘图’":最小生成树(无向图)

    本文主要参考自<算法>. 加权图是一种为每条边关联一个权值或是成本的图模型.这种图能够自然地表示许多应用.在一幅航空图中,边表示航线,权值则可以表示距离或是费用.在一幅电路图中,边表示导线 ...

  4. C语言实现某年某月某日是某年的第几天

    看到这个标题,想实现这样的功能其实挺简单的,用C语言的switch语句加上闰年,平年条件的判断,再加上一定的逻辑可以轻松实现这样的函数,在linux内核中,存在判断闰年平年的接口,我将它移植出来后,写 ...

  5. 一个简单的ruby生成器例子(用连续体Continuation实现)

    ruby中有很多经典的驱动器结构,比如枚举器和生成器等.这次简单介绍下生成器的概念.生成器是按照功能要求,一次产生一个对象,或称之为生成一个对象的方法.ruby中的连续体正好可以用来完成生成器的功能. ...

  6. python 3下基于select模型的事件驱动机制程序

    它的基本原理就是select/epoll这个function会不断的轮询所负责的所有socket,当某个socket有数据到达了,就通知用户进程.它的流程如图: 当用户进程调用了select,那么整个 ...

  7. python标准库Beautiful Soup与MongoDb爬喜马拉雅电台的总结

    Beautiful Soup标准库是一个可以从HTML/XML文件中提取数据的Python库,它能够通过你喜欢的转换器实现惯用的文档导航,查找,修改文档的方式,Beautiful Soup将会节省数小 ...

  8. Java + Selenium + TestNG + Maven

    环境准备: 1. Java: Install Java jdk: Version: java 1.8 or aboveConfigure Java Environment Variables:Add ...

  9. 为何90%的IT技术人员不适合做老大

    老男孩老师终于写了一篇让我觉得不错的文章,哈哈,转一下. 什么是格局? 格局就是能够很好的平衡短期利益和长期利益. 过分注重短期利益的人必然会失去长期利益,到头来一定会很普通. 例如:跳槽不断,可能短 ...

  10. 数据库中row_number()、rank()、dense_rank() 的区别

    row_number的用途非常广泛,排序最好用它,它会为查询出来的每一行记录生成一个序号,依次排序且不会重复,注意使用row_number函数时必须要用over子句选择对某一列进行排序才能生成序号. ...