NOIP模拟1717 总结
总结
T1: 有x个人在a时b分来,c时d分离开,求所有时刻中人数的最大值。
差分裸题,当然也可以写线段树。
第一题一般来说思维都不会太复杂,如果打的时间很长,便要调整自己的思路,要保证A掉。
T2: 对一个数组进行新定义的排序:选出数组中的不和谐数(严格小于左边第一个数(左边有数)或严格大于右边第一个数(右边有数)),将其一起删掉,重复操作直到不存在不和谐数。
双向链表的运用:先在第一遍中将需要删除的数加入删除列表,然后循环处理删除列表至其为空:将每一段的左右两边的第一个加入检查列表(删除过后会改变相邻关系,但每删除一段连续的下降序列只会影响其左右两端)只加入左右两边,保证复杂度,将删除列表清空,然后再来遍历检查列表,将检查列表中的不符合的加入删除列表,一遍下一次遍历。
此题爆0,因为我以为自己写的是正解,于是不屑于打对拍(!!!亏啊)——越是简单的题,越要保证正确。
T3: 只有两个颜色的祖玛游戏(连续的三个可以消除,可以向任意位置插入一个)。求最小消除次数。
读题就觉得和bzoj的一道错题很像。。消除类型的多半就是区间dp,但此题的转移情况有4种,要不重不漏的转移完全才能A掉。
- 将原序列进行压缩,相同的一段用一个点表示,并记录其包含的个数sze。
- 分类写出方程 :
\]
\]
\]
\]
时间复杂度\(O(n^3)\)
本题情况考虑完了,但是转移的不够干净利落,考试只得了60分。刚刚复习完区间dp,做的题还没有达到这种难度,dp题要多刷,多总结其中的奥妙。
code
T1
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
namespace IO{
inline int read(){
int i = 0, f = 1; char ch = getchar();
for(; (ch < '0' || ch > '9') && ch != '-'; ch = getchar());
if(ch == '-') f = -1, ch = getchar();
for(; ch >= '0' && ch <= '9'; ch = getchar()) i = (i << 3) + (i << 1) + (ch - '0');
return i * f;
}
inline void wr(long long x){
if(x < 0) putchar('-'), x = -x;
if(x > 9) wr(x / 10);
putchar(x % 10 + '0');
}
}using namespace IO;
const int N = 1e5 + 5, M = 2000, OO = 0x3f3f3f3f;
typedef long long ll;
ll sum[M], ans;
int n, maxx, minn;
int main(){
n = read(); minn = OO, maxx = 0;
for(int i = 1 ; i <= n; i++){
int x = read(), a = read(), b = read(), c = read(), d = read();
sum[a * 60 + b] += x;
sum[c * 60 + d] -= x;
minn = min(minn, a * 60 + b);
maxx = max(maxx, c * 60 + d);
}
for(int i = minn; i <= maxx; i++) sum[i] = sum[i - 1] + sum[i], ans = max(ans, sum[i]);
wr(ans), putchar('\n');
return 0;
}
T2
#include<bits/stdc++.h>
using namespace std;
namespace IO{
inline int read(){
int i = 0, f = 1; char ch = getchar();
for(; (ch < '0' || ch > '9') && ch != '-'; ch = getchar());
if(ch == '-') f = -1, ch = getchar();
for(; ch >= '0' && ch <= '9'; ch = getchar()) i = (i << 3) + (i << 1) + (ch - '0');
return i * f;
}
inline void wr(int x){
if(x < 0) putchar('-'), x = -x;
if(x > 9) wr(x / 10);
putchar(x % 10 + '0');
}
}using namespace IO;
const int N = 1E6 + 5;
int n, T, head;
struct node{int last, nxt, val;}bdList[N];
vector<int> delList, chckList, ans;
bool del[N], chck[N];
inline bool gg(int k){
int last = bdList[k].last, nxt = bdList[k].nxt;
if(last > 0 && bdList[last].val > bdList[k].val) return true;
if(nxt < n + 1 && bdList[nxt].val < bdList[k].val) return true;
return false;
}
inline void dele(int k){
int last = bdList[k].last, nxt = bdList[k].nxt;
if(head == k) head = nxt;
if(last > 0) bdList[last].nxt = nxt;
if(nxt < n + 1) bdList[nxt].last = last;
}
int main() {
T = read();
while(T--){
n = read();
delList.clear(), chckList.clear(), memset(bdList, 0, sizeof bdList), memset(del, 0, sizeof del), memset(chck, 0, sizeof chck);
for(int i = 1; i <= n; i++)
bdList[i].last = i - 1, bdList[i].nxt = i + 1, bdList[i].val = read();
head = 1;
for(int i = 1; i <= n; i++)
if(gg(i)) delList.push_back(i), del[i] = true;
while(delList.size()){
for(int i = delList.size() - 1; i >= 0; i--) {
int last = bdList[delList[i]].last, nxt = bdList[delList[i]].nxt;
if(last > 0 && !del[last] && !chck[last]) chckList.push_back(last), chck[last] = true;
if(nxt < n + 1 && !del[nxt] && !chck[nxt]) chckList.push_back(nxt), chck[nxt] = true;
dele(delList[i]);
}
delList.clear();
for(int i = chckList.size() - 1; i >= 0; i--){
chck[chckList[i]] = false;
if(gg(chckList[i])) delList.push_back(chckList[i]), del[chckList[i]] = true;
}
chckList.clear();
}
ans.clear();
for(; head <= n; head = bdList[head].nxt) ans.push_back(bdList[head].val);
cout<<ans.size()<<endl;
for(int i = 0; i < ans.size(); i++) cout<<ans[i]<<" ";cout<<endl;
}
return 0;
}
T3
#include<bits/stdc++.h>
using namespace std;
namespace IO{
inline int read(){
int i = 0, f = 1; char ch = getchar();
for(; (ch < '0' || ch > '9') && ch != '-'; ch = getchar());
if(ch == '-') f = -1, ch = getchar();
for(; ch >= '0' && ch <= '9'; ch = getchar()) i = (i << 3) + (i << 1) + (ch - '0');
return i * f;
}
inline void wr(int x){
if(x < 0) putchar('-'), x = -x;
if(x > 9) wr(x / 10);
putchar(x % 10 + '0');
}
}using namespace IO;
const int N = 205, OO = 0x3f3f3f3f;
int n, T, head;
int dp[N][N], sze[N];
char M[N], S[N];
inline int DP(int l, int r){
if(dp[l][r] != -1) return dp[l][r];
if(l == r) return dp[l][r] = 3 - sze[l];
dp[l][r] = OO;
if(S[l] == S[r]){
dp[l][r] = min(dp[l][r], DP(l + 1, r - 1) + max(0, 3 - sze[l] - sze[r]));
if(sze[l] + sze[r] != 4)
for(int k = l + 1; k <= r - 1; k++)
if(sze[k] == 1 && S[k] == S[l]) dp[l][r] = min(dp[l][r], DP(l + 1, k - 1) + DP(k + 1, r - 1));
}
for(int k = l; k < r; k++)
dp[l][r] = min(dp[l][r], DP(l, k) + DP(k + 1, r));
return dp[l][r];
}
int main(){
T = read();
while(T--){
scanf("%s", M + 1);
int len = strlen(M + 1), cnt = 0;
for(int i = 1; i <= len; i++)
if(M[i] == M[i - 1]) sze[cnt]++;
else sze[++cnt] = 1, S[cnt] = M[i];
memset(dp, -1, sizeof dp);
wr(DP(1, cnt)), putchar('\n');
}
return 0;
}
NOIP模拟1717 总结的更多相关文章
- NOIP模拟赛20161022
NOIP模拟赛2016-10-22 题目名 东风谷早苗 西行寺幽幽子 琪露诺 上白泽慧音 源文件 robot.cpp/c/pas spring.cpp/c/pas iceroad.cpp/c/pas ...
- contesthunter暑假NOIP模拟赛第一场题解
contesthunter暑假NOIP模拟赛#1题解: 第一题:杯具大派送 水题.枚举A,B的公约数即可. #include <algorithm> #include <cmath& ...
- NOIP模拟赛 by hzwer
2015年10月04日NOIP模拟赛 by hzwer (这是小奇=> 小奇挖矿2(mining) [题目背景] 小奇飞船的钻头开启了无限耐久+精准采集模式!这次它要将原矿运到泛光之源的矿 ...
- 大家AK杯 灰天飞雁NOIP模拟赛题解/数据/标程
数据 http://files.cnblogs.com/htfy/data.zip 简要题解 桌球碰撞 纯模拟,注意一开始就在袋口和v=0的情况.v和坐标可以是小数.为保险起见最好用extended/ ...
- 队爷的讲学计划 CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的讲学计划 题解:刚开始理解题意理解了好半天,然后发 ...
- 队爷的Au Plan CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的Au%20Plan 题解:看了题之后觉得肯定是DP ...
- 队爷的新书 CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的新书 题解:看到这题就想到了 poetize 的封 ...
- CH Round #58 - OrzCC杯noip模拟赛day2
A:颜色问题 题目:http://ch.ezoj.tk/contest/CH%20Round%20%2358%20-%20OrzCC杯noip模拟赛day2/颜色问题 题解:算一下每个仆人到它的目的地 ...
- CH Round #52 - Thinking Bear #1 (NOIP模拟赛)
A.拆地毯 题目:http://www.contesthunter.org/contest/CH%20Round%20%2352%20-%20Thinking%20Bear%20%231%20(NOI ...
随机推荐
- Android 获取联系人手机号码、姓名、地址、公司、邮箱、生日
public void testGetAllContact() throws Throwable { //获取联系人信息的Uri Uri uri = ContactsContract.Contacts ...
- android 消息系统Handler、MessageQueue、Looper源代码学习
android消息系统 总体框架如图所看到的 在安卓的消息系统中,每一个线程有一个Looper,Looper中有一个MessageQueue,Handler向这个队列中投递Message,Looper ...
- __block typeof的说明
1. block不是Object对象,所以对retain无效,要想保留block生命周期,最好通过copy来实现,当然copy后,要记得release. 2.一般被block的应用的对象,retain ...
- HDU 1018 Big Number 数学题解
Problem Description In many applications very large integers numbers are required. Some of these app ...
- TCP快速重传与快速恢复原理分析(四种不同的算法)
在TCP/IP中,快速重传和恢复(fast retransmit and recovery,FRR)是一种拥塞控制算法,它能快速恢复丢失的数据包.没有FRR,如果数据包丢失了,TCP将会使用定时器来要 ...
- C#添加水印
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Secu ...
- [Angular2 Form] Reactive Form, FormBuilder
Import module: import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/comm ...
- [Angular2 Router] Auxiliary Routes bit by bit
Article Github Auxiliary Routes is is little bit hard to understand. Here is demo, link You can see ...
- Understanding Cubert Concepts(一)Partitioned Blocks
Understanding Cubert Concepts(一)Partitioned Blocks Cubert Concepts 对于Cubert,我们要理解其核心的一些概念,比方BLOCK.这些 ...
- 【u237】分数化小数
Time Limit: 1 second Memory Limit: 128 MB [问题描述] 写一个程序,输入一个形如N/D的分数(N是分子,D是分母),输出它的小数形式.如果小数有循环节的话,把 ...