题目链接:

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. MySql常用操作语句(2:数据库、表管理以及数据操作)

    本文主要内容转自一博文. 另外可供参考资源: SQL语句教程 SQL语法 1.数据库(database)管理  1.1 create 创建数据库 mysql> create database f ...

  2. MTK 快速开机 技术详解

    Android version 2.3.5 首先查看Settings里控制开关 01 // 获取当前状态 02 boolean ipoSettingEnabled = Settings.System. ...

  3. PS 滤镜算法原理——照亮边缘

    这个算法原理很简单,对彩色图像的R,G,B 三个通道,分别求梯度,然后将梯度值作为三个通道的值. clc; clear all;Image=imread('4.jpg');Image=double(I ...

  4. javascript、ruby和C性能一瞥(2)

    好吧,最后让我们用C来实现,看看再能榨取多少性能.注意我没有改变算法,C的算法和之前的3种都是基本相同的: #include <stdio.h> #include <stdlib.h ...

  5. LeetCode(48)-Length of Last Word

    题目: Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return t ...

  6. Redis客户端ServiceStack.Redis的简单使用

    在nuget中下载ServiceStack.Redis,但是运行之后会出现一个问题: Exception: "Com.JinYiWei.Cache.RedisHelper"的类型初 ...

  7. C#中使用双缓冲来避免绘制图像过程中闪烁

    自己所做项目中,在显示医学图像的界面中,当鼠标拖动图像时,不断刷新从后台获取新的图像,而整个过程就很诡异,一直闪个不停. 找到的一个可行方法是:在用户控件的构造函数中加入以下代码: SetStyle( ...

  8. oracle 修改 字段名称

    暂时应该没有对应的方法,所以我用自己想好的方法去修改 /*修改原字段名name为name_tmp,是将想改名称的字段改为没用/临时的字段*/ Alter  table 表名 rename column ...

  9. Java Web开发中路径问题小结

     Java Web开发中,路径问题是个挺麻烦的问题,本文小结了几个常见的路径问题,希望能对各位读者有所帮助. (1) Web开发中路径的几个基本概念 假设在浏览器中访问了如下的页面,如图1所示: 图1 ...

  10. Odoo 学习 【二】Environment 概览

    Environment 参考链接: http://odoo-new-api-guide-line.readthedocs.io/en/latest/environment.html#environme ...