18年11月5日 NOIP模拟赛
T1
题解
对于k=100的情况,贪心
对于100%的数据
可以发现,当前的决策只对后面的开采有影响,且剩余耐久度与之后的开采收益成正比,如果倒着考虑这个问题,得出i-n的星球1点耐久度所能获得的最大收益,从后往前dp,得出最大值最后乘w就是答案
代码
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=100001;
int n,w,t[maxn],a[maxn];
double k,c,ans;
int main()
{
//freopen("exploit.in","r",stdin);
//freopen("exploit.out","w",stdout);
scanf("%d%lf%lf%d",&n,&k,&c,&w);
k=1-0.01*k;c=1+0.01*c;
for(int i=1;i<=n;i++)scanf("%d%d",&t[i],&a[i]);
for(int i=n;i;i--)
if(t[i]==1)
ans=max(ans,ans*k+a[i]);
else
ans=max(ans,ans*c-a[i]);
printf("%.2lf\n",ans*w);
}
T2
题解
从前往后推出每个人最少/最多有几个和第一个人相同的勋章
然后看最后一个最少是否是0即可
代码
#include<bits/stdc++.h>
inline int read()
{
int x = 0,t = 1; char ch = getchar();
while(ch < '0' || ch > '9'){if(ch == '-') t = -1; ch = getchar();}
while(ch >= '0' && ch <= '9'){x = x*10+ch-'0'; ch = getchar();}
return x*t;
}
const int MAXN = 20010;
int n;
int num[MAXN];
int L,R,mid;
int dp[MAXN],gun[MAXN];
inline void init()
{
n = read();
for(int i=1;i<=n;i++)
num[i] = read();
for(int i=1;i<n;i++)
L=std::max(L,num[i]+num[i+1]);
L=std::max(L,num[n]+num[1]),R=0x7ffffff;
}
inline void DP()
{
while(L<R)
{
mid=(L+R)>>1;
dp[1]=gun[1]=num[1];
for(int i=2;i<=n;i++)
dp[i]=std::min(num[i],num[1]-gun[i-1]),
gun[i]=std::max(0,num[i]-(mid-num[i-1]-(num[1]-dp[i-1])));
if(gun[n]==0) R=mid;
else L=mid+1;
}
std::cout << L;
}
int main(void)
{
std::ios_base::sync_with_stdio(false);
init();
DP();
return 0;
}
T3
题解
30%: O(n ^ 2 * m)暴力判断。
100%: 很显然答案的可能性最多只有n 种,所以我们将所有人的答案按字典序排序后枚举
将每个人的答案作为正确答案来进行判断。由于是判断题,若当前人的答案为正确答
案则零分者的答案也就确定了,那么只需统计出这两种答案的人数判断是否满足题意
即可。这一步使用字符串哈希即可解决。
另外要注意p = 0 和p = q = 0 的情况。
代码
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
const int N = 3e4 + 2, M = 5e2 + 2, sed = 31, SED = 131, mod = 70177, MOD = 92311;
int n, m, p, q, ans, hash[N], HASH[N];
int top, info[mod], nxt[N * 2], fet[N * 2], cnt[N * 2];
struct node {
char s[M];
inline bool operator < (const node &b) const {
return strcmp(s, b.s) < 0;
}
} a[N];
inline void Insert(const int &x, const int &y) {
for (int k = info[x]; k; k = nxt[k])
if (fet[k] == y) {
++cnt[k]; return ;
}
nxt[++top] = info[x]; info[x] = top;
fet[top] = y; cnt[top] = 1;
return ;
}
inline int Query(const int &x, const int &y) {
for (int k = info[x]; k; k = nxt[k])
if (fet[k] == y) return cnt[k];
return 0;
}
inline void Solve1() {
int tmp, TMP; ans = -1;
for (int i = 0; i < n; ++i) {
tmp = TMP = 0;
for (int j = 0; j < m; ++j) {
tmp = (tmp * sed + (a[i].s[j] == 'N')) % mod;
TMP = (TMP * SED + (a[i].s[j] == 'N')) % MOD;
}
hash[i] = tmp, HASH[i] = TMP;
Insert(tmp, TMP);
}
for (int i = 0; i < n; ++i)
if (Query(hash[i], HASH[i]) == p) {
tmp = TMP = 0;
for (int j = 0; j < m; ++j) {
tmp = (tmp * sed + (a[i].s[j] == 'Y')) % mod;
TMP = (TMP * SED + (a[i].s[j] == 'Y')) % MOD;
}
if (Query(tmp, TMP) == q) {
ans = i; break;
}
}
if (ans != -1) printf("%s\n", a[ans].s);
else puts("-1");
return ;
}
char cur[M];
inline void Solve2() {
int tmp, TMP; ans = -1;
for (int i = 0; i < n; ++i) {
tmp = TMP = 0;
for (int j = 0; j < m; ++j) {
tmp = (tmp * sed + (a[i].s[j] == 'N')) % mod;
TMP = (TMP * SED + (a[i].s[j] == 'N')) % MOD;
}
hash[i] = tmp, HASH[i] = TMP;
Insert(tmp, TMP);
}
for (int i = n - 1; i >= 0; --i)
if (Query(hash[i], HASH[i]) == q) {
tmp = TMP = 0;
for (int j = 0; j < m; ++j) {
tmp = (tmp * sed + (a[i].s[j] == 'Y')) % mod;
TMP = (TMP * SED + (a[i].s[j] == 'Y')) % MOD;
}
if (Query(tmp, TMP) == p) {
ans = i; break;
}
}
if (ans != -1) {
for (int i = 0; i < m; ++i)
cur[i] = a[ans].s[i] == 'N' ? 'Y' : 'N';
printf("%s\n", cur);
}
else puts("-1");
return ;
}
void Solve3() {
int tmp, TMP;
for (int i = 0; i < n; ++i) {
tmp = TMP = 0;
for (int j = 0; j < m; ++j) {
tmp = (tmp * sed + (a[i].s[j] == 'N')) % mod;
TMP = (TMP * SED + (a[i].s[j] == 'N')) % MOD;
}
Insert(tmp, TMP);
tmp = TMP = 0;
for (int j = 0; j < m; ++j) {
tmp = (tmp * sed + (a[i].s[j] == 'Y')) % mod;
TMP = (TMP * SED + (a[i].s[j] == 'Y')) % MOD;
}
Insert(tmp, TMP);
}
bool flag = true;
for (int i = 0; i < m; ++i) cur[i] = 'N';
do {
tmp = TMP = 0;
for (int j = 0; j < m; ++j) {
tmp = (tmp * sed + (cur[j] == 'N')) % mod;
TMP = (TMP * SED + (cur[j] == 'N')) % MOD;
}
if (Query(tmp, TMP) == 0) {
flag = true; break;
}
flag = false;
for (int j = m - 1; j >= 0; --j)
if (cur[j] == 'Y') cur[j] = 'N';
else {
cur[j] = 'Y'; flag = true; break;
}
} while (flag);
if (flag) printf("%s\n", cur);
else puts("-1");
return ;
}
int main() {
//freopen("answer.in", "r", stdin);
//freopen("answer.out", "w", stdout);
scanf("%d%d%d%d", &n, &m, &p, &q);
for (int i = 0; i < n; ++i) scanf("%s", a[i].s);
sort(a, a + n);
if (p) Solve1();
else if (q) Solve2();
else Solve3();
fclose(stdin); fclose(stdout);
return 0;
}
18年11月5日 NOIP模拟赛的更多相关文章
- 18年10月31日 NOIP模拟赛
T1.exercise 题解 数据很小直接模拟 代码 #include<iostream> #include<cstdio> #include<cmath> #in ...
- 18年10月30日 NOIP模拟赛
T1 jkl 题解 显然每次都取a[i]的最大值/最小值,并更新a[i]即可 用数据结构维护这一操作..得分看常数 事实上用v[i]记录权值为i的个数,然后for乱搞就可以了... 其它乱搞做法能获得 ...
- 9月24日noip模拟赛解题报告
1.校门外的树(tree.c/cpp/pas 128M,1s) Description LSGJ扩建了,于是校门外有了一条长为L的路.路上种了一排的树,每相邻两棵树之间的距离为1,我们可以把马路看成一 ...
- NOIP2017年11月9日赛前模拟
最后一次NOIP模拟了····· 题目1:回文数字 Tom 最近在研究回文数字. 假设 s[i] 是长度为 i 的回文数个数(不含前导0),则对于给定的正整数 n 有:
- NOIP模拟赛 by hzwer
2015年10月04日NOIP模拟赛 by hzwer (这是小奇=> 小奇挖矿2(mining) [题目背景] 小奇飞船的钻头开启了无限耐久+精准采集模式!这次它要将原矿运到泛光之源的矿 ...
- 2016年11月27日 星期日 --出埃及记 Exodus 20:18
2016年11月27日 星期日 --出埃及记 Exodus 20:18 When the people saw the thunder and lightning and heard the trum ...
- 2016年11月2日 星期三 --出埃及记 Exodus 19:18
2016年11月2日 星期三 --出埃及记 Exodus 19:18 Mount Sinai was covered with smoke, because the LORD descended on ...
- 北京Uber优步司机奖励政策(11月23日~11月29日)
用户组:人民优步"关羽组"(适用于11月23日-11月29日)奖励政策: 滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最 ...
- 北京Uber优步司机奖励政策(11月16日~11月22日)
用户组:人民优步“关羽组”(适用于11月16日-11月22日)奖励政策: 滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/ ...
随机推荐
- 学习ThinkPHP笔记
学习ThinkPHP笔记 TP的模块化设计 名称 描述 应用 基于同一个入口文件访问的项目我们称之为一个应用. 模块 一个应用下面可以包含多个模块,每个模块在应用目录下面都是一个独立的子目录. 控制器 ...
- C# 抓取网页内容的方法
1.抓取一般内容 需要三个类:WebRequest.WebResponse.StreamReader 所需命名空间:System.Net.System.IO 核心代码: view plaincopy ...
- springcloud-feign的hystrix支持
关于hystrix的介绍,可以看我的上篇博客:springcloud-断路器hystrixs 本文主要介绍在feign中,如何使用hystrix 1.pom依赖 <dependency> ...
- Jsp&Servlet入门级项目全程实录第6讲
惯例广告一发,对于初学真,真的很有用www.java1234.com,去试试吧! 1.建立数据表及数据(略) 2.创建student model package com.java1234.model; ...
- 用于深拷贝的扩展方法 C#
using System.Runtime.Serialization.Formatters.Binary; using System.IO; public static class Tool { pu ...
- 啰里吧嗦redis
1.redis是什么 redis官网地址 Redis is an open source (BSD licensed), in-memory data structure store, used as ...
- java并发编程的艺术(二)---重排序与volatile、final关键字
本文来源于翁舒航的博客,点击即可跳转原文观看!!!(被转载或者拷贝走的内容可能缺失图片.视频等原文的内容) 若网站将链接屏蔽,可直接拷贝原文链接到地址栏跳转观看,原文链接:https://www.cn ...
- Microservices与DDD的关系
Microservices(微服务架构)和DDD(领域驱动设计)是时下最炙手可热的两个技术词汇.在最近两年的咨询工作中总是会被不同的团队和角色询问,由此也促使我思考为什么这两个技术词汇被这么深入人心的 ...
- 深入浅出图解【计算机网络】 之 【TCP可靠传输的实现2: 超时重传+拥塞控制】
[前言]上一篇文章介绍了关于TCP的基础知识,以及建立(释放)连接和滑动窗口的概念. 本篇文章将延续上一篇的思路,继续介绍TCP实现可靠传输的机制. 超时重传 上一篇文章里介绍过TCP采用停止等待协议 ...
- thymeleaf 标签使用方法
使用thymeleaf首先添加依赖,<dependency><groupId>org.springframework.boot</groupId><artif ...