题目链接:

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开发机器上的配置及zookeeper配置

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

  2. C#中任意类型数据转成JSON格式

    /// <summary>    /// List转成json     /// </summary>    /// <typeparam name="T&quo ...

  3. linux命令大全(自己慢慢看)

    http://blog.zol.com.cn/874/article_873769.html rm -rf mydir /* 删除mydir目录 */ cd mydir /* 进入mydir目录 */ ...

  4. C/C++语言中NULL、'\0’和0的区别

    注:本文参考了http://blog.csdn.net/mylinx/article/details/6873253及书籍<征服C指针>([日]前桥和弥著). NULL.'\0'和0的值是 ...

  5. 一键安装 redmine on rhel6.4

    一键安装 redmine on rhel6.4 一键式安装redmine省去了大量不必要的时间.下载:bitnami-redmine-2.5.2-1-linux-x64-installer.run. ...

  6. 苹果新的编程语言 Swift 语言进阶(十五)--协议

    协议定义了适合某个特定任务或功能需要的方法.属性和其它需求的一个蓝图.协议本身不提供这些需求的实现,它只是描述了一个任务或功能实现的蓝图. 协议与java 语言中的接口定义类似,都是描述了一个实现可以 ...

  7. Objective-C的面向对象特性(一)

    Objective-C在c语言的基础上增加了面向对象特性,都有哪些面向对象特性呢? 其中第一个最重要的特性是类和对象的实现. Objective-C软件由许多对象构成,形成一个对象网络,对象之间通过发 ...

  8. Leetcode_263_Ugly Number

    本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/49431329 Write a program to che ...

  9. mac os x下的一些小技巧

    1显示swap空间: sysctl vm.swapusage 其中sysctl中有很多可以控制和查看的项,可以通过sysctl -A列举,另外可以通过man sysctl来查看. 而实际swap文件和 ...

  10. javascript访问html元素的内容(2)

    对于(1)中最后一个包装方式创建的是一个方法,我们必须以方法调用的方式来使用它,这和其他默认的以属性返回结果略有不同,如果有强迫症的童鞋有些伤不起,那么我们下面就把它实现为属性返回的方式: //chi ...