Codeforces 957 水位标记思维题
A
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
const double EPS = 1.0e-4;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
string a;
int anser = ;
int main()
{
int n;
cin >> n;
cin >> a;
int len = a.size();
for (int i = ; i < len - ; i++)
{
if (a[i] == a[i + ] && a[i] != '?')
{
cout << "No" << endl;
return ;
}
}
if (a[] == '?' || a[len - ] == '?')
{
cout << "Yes" << endl;
return ;
}
for (int i = ; i < len - ; i++)
{
if (a[i] == '?' && (a[i - ] == a[i + ]))
{
cout << "Yes" << endl;
return ;
}
}
for (int i = ; i < len - ; i++)
{
if (a[i] == a[i + ] && a[i] == '?')
{
cout << "Yes" << endl;
return ;
}
}
cout << "No" << endl;
}
B
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
const double EPS = 1.0e-4;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
char f[][];
int hang[];
int main()
{
int n, m;
int sum = ;
cin >> n >> m;
for (int i = ; i <= n; i++)
{
scanf("%s", f[i] + );
}
for (int i = ; i <= n; i++)
{
if (hang[i])
{
continue;
}
for (int j = ; j <= m; j++)
{
if (f[i][j] == '#')
{
//cout << i << " " << j << endl;
for (int k = ; k <= n; k++)
{
if (k == i)
{
continue;
}
if (f[k][j] == '#')
{
// cout << "find" << k << " " << j << endl;
for (int w = ; w <= m; w++)
{
if (f[k][w] != f[i][w])
{
cout << "No" << endl;
return ;
}
}
hang[k] = ;
}
}
}
}
}
cout << "Yes" << endl;
return ;
}
C
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
const double EPS = 1.0e-4;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
int num[];
int main()
{
double anser = -;
int n, u;
cin >> n >> u;
num[n + ] = INT_MAX;
for (int i = ; i <= n; i++)
{
scanf("%d", num + i);
}
for (int i = ; i <= n - ; i++)
{
int now = num[i];
int cha = num[i + ] - num[i];
int aim = upper_bound(num + , num + n + , num[i] + u) - num - ;
if (aim - i <= || aim > n)
{
continue;
}
//cout << i << " " << aim << endl;
anser = max(anser, (double)(num[aim] - num[i] - cha) / (double)(num[aim] - num[i]));
}
if (anser == -)
{
cout << anser << endl;
}
else
{
printf("%.10f\n", anser);
}
return ;
}
D

假设在第i次量的时候的总标记数为sum[i] 可知其必定为非递减函数 sum[i]=d[i]+m[i]+1
要使d[i]的总值最小则 要在m[i]+1上面再加数使得 m[i]>=m[i-1]&&m[i+1]-1<=m[i]<=m[i+1]
先从前往后扫一遍满足第一个条件 再从往前扫一遍满足第二个条件
注意要开LL
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
const double EPS = 1.0e-4;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
ll num[];
int main()
{
int n;
cin >> n;
ll maxn = - ;
ll ans = ;
for (int i = ; i <= n; i++)
{
scanf("%lld", num + i);
maxn = max(maxn, num[i]);
}
for (int i = ; i <= n - ; i++)
{
if (num[i + ] < num[i])
{
ans += num[i] - num[i + ];
num[i + ] = num[i];
}
}
for (int i = n; i >= ; i--)
{
if (num[i] - num[i - ] > )
{
ans += num[i] - - num[i - ];
num[i - ] = num[i] - ;
}
}
cout << ans << endl;
return ;
}
Codeforces 957 水位标记思维题的更多相关文章
- CF--思维练习-- CodeForces - 215C - Crosses(思维题)
ACM思维题训练集合 There is a board with a grid consisting of n rows and m columns, the rows are numbered fr ...
- Codeforces 675C Money Transfers 思维题
原题:http://codeforces.com/contest/675/problem/C 让我们用数组a保存每个银行的余额,因为所有余额的和加起来一定为0,所以我们能把整个数组a划分为几个区间,每 ...
- Codeforces 1090D - Similar Arrays - [思维题][构造题][2018-2019 Russia Open High School Programming Contest Problem D]
题目链接:https://codeforces.com/contest/1090/problem/D Vasya had an array of n integers, each element of ...
- codeforces 1140D(区间dp/思维题)
D. Minimum Triangulation time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- ACM思维题训练 Section A
题目地址: 选题为入门的Codeforce div2/div1的C题和D题. 题解: A:CF思维联系–CodeForces -214C (拓扑排序+思维+贪心) B:CF–思维练习-- CodeFo ...
- codeforces ~ 1009 B Minimum Ternary String(超级恶心的思维题
http://codeforces.com/problemset/problem/1009/B B. Minimum Ternary String time limit per test 1 seco ...
- 贪心/思维题 Codeforces Round #310 (Div. 2) C. Case of Matryoshkas
题目传送门 /* 题意:套娃娃,可以套一个单独的娃娃,或者把最后面的娃娃取出,最后使得0-1-2-...-(n-1),问最少要几步 贪心/思维题:娃娃的状态:取出+套上(2),套上(1), 已套上(0 ...
- C. Nice Garland Codeforces Round #535 (Div. 3) 思维题
C. Nice Garland time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- CodeForces - 631C ——(思维题)
Each month Blake gets the report containing main economic indicators of the company "Blake Tech ...
随机推荐
- React Native商城项目实战02 - 主要框架部分(tabBar)
1.安装插件,cd到项目根目录下执行: $ npm i react-native-tab-navigator --save 2.主框架文件Main.js /** * 主页面 */ import Rea ...
- java 栈和栈帧
文章转载自:http://www.tuicool.com/articles/URZrMnb jvm为每个新创建的线程都分配一个堆栈.堆栈以帧为单位保存线程的状态.jvm对堆栈只进行两种操作:以帧为单位 ...
- solr的访问权限管理及ubuntu下iptables的设置
Apache Solr 是一个开源的搜索服务器,该平台默认允许匿名访问,攻击者可读取平台中各类敏感信息.之前考虑过增加账号密码访问,但是没有搞定,所以采用了曲线救国的方式,设置solr服务器只允许部分 ...
- CANopen的相关学习
CANopen是一种架构在控制局域网路(Controller Area Network, CAN)上的高层通讯协定,包括通讯子协定及设备子协定常在嵌入式系统中使用,也是工业控制常用到的一种现场总线. ...
- ABAP基本数据类型
ABAP 程序中共包含8种基本数据类型: 数据类型名称 描述 属 性 C Character Text(字符类型) 默认长度=1,默认值=blank,最大长度无限制 N Numeric Text(数 ...
- Elasticsearch 安装head插件
一.简介 elasticsearch-head是一个界面化的集群操作和管理工具,可以对集群进行傻瓜式操作.你可以通过插件把它集成到es(首选方式),也可以安装成一个独立webapp. Elastics ...
- frewalld假端口
之前服务器没有开启firewalld,上面有lnmp.zabbix服务,后来开启了防火墙,发现端口都在,但是不能访问zabbix,后来用firewalld把端口重新开启.重新加载后才可以访问,这就是f ...
- MAVEN打包时跳过Junit测试
我们知道,通常情况下使用maven package命令打包时,会自动执行test包下的各个单元测试. 这是因为spring-boot-maven-plugin插件已经集成了maven-surefire ...
- LeetCode算法题-Magic Squares In Grid(Java实现)
这是悦乐书的第326次更新,第349篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第196题(顺位题号是840).3 x 3魔方是一个3 x 3网格,填充了从1到9的不同 ...
- MySQL学习-数据库设计以及sql的进阶语句
1.数据库设计 关系型数据库建议在E-R模型的基础上,我们需要根据产品经理的设计策划,抽取出来模型与关系,制定出表结构,这是项目开始的第一步 在开发中有很多设计数据库的软件,常用的如power des ...