总结

T1: 有x个人在a时b分来,c时d分离开,求所有时刻中人数的最大值。

差分裸题,当然也可以写线段树。

第一题一般来说思维都不会太复杂,如果打的时间很长,便要调整自己的思路,要保证A掉。

T2: 对一个数组进行新定义的排序:选出数组中的不和谐数(严格小于左边第一个数(左边有数)或严格大于右边第一个数(右边有数)),将其一起删掉,重复操作直到不存在不和谐数。

双向链表的运用:先在第一遍中将需要删除的数加入删除列表,然后循环处理删除列表至其为空:将每一段的左右两边的第一个加入检查列表(删除过后会改变相邻关系,但每删除一段连续的下降序列只会影响其左右两端)只加入左右两边,保证复杂度,将删除列表清空,然后再来遍历检查列表,将检查列表中的不符合的加入删除列表,一遍下一次遍历。

此题爆0,因为我以为自己写的是正解,于是不屑于打对拍(!!!亏啊)——越是简单的题,越要保证正确。

T3: 只有两个颜色的祖玛游戏(连续的三个可以消除,可以向任意位置插入一个)。求最小消除次数。

读题就觉得和bzoj的一道错题很像。。消除类型的多半就是区间dp,但此题的转移情况有4种,要不重不漏的转移完全才能A掉。

  1. 将原序列进行压缩,相同的一段用一个点表示,并记录其包含的个数sze。
  2. 分类写出方程 :

\[dp[l][r] = min(dp[l][r], 3 - sze[l]) (l == r)
\]

\[dp[l][r] = min(dp[l][r], dp[l][k], dp[k + 1][r] (l \le k < r)
\]

\[dp[l][r] = min(dp[l][r], do[l + 1][k - 1] + dp[k + 1][r - 1]) (col[l] == col[r] \&\& sze[l] + sze[r] != 4 \&\& sze[k] == 1, (l < k < r))
\]

\[dp[l][r] = min(dp[l][r], do[l + 1][r - 1] + max(0, 3 - sze[l] - sze[r]))
\]

时间复杂度\(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 总结的更多相关文章

  1. NOIP模拟赛20161022

    NOIP模拟赛2016-10-22 题目名 东风谷早苗 西行寺幽幽子 琪露诺 上白泽慧音 源文件 robot.cpp/c/pas spring.cpp/c/pas iceroad.cpp/c/pas ...

  2. contesthunter暑假NOIP模拟赛第一场题解

    contesthunter暑假NOIP模拟赛#1题解: 第一题:杯具大派送 水题.枚举A,B的公约数即可. #include <algorithm> #include <cmath& ...

  3. NOIP模拟赛 by hzwer

    2015年10月04日NOIP模拟赛 by hzwer    (这是小奇=> 小奇挖矿2(mining) [题目背景] 小奇飞船的钻头开启了无限耐久+精准采集模式!这次它要将原矿运到泛光之源的矿 ...

  4. 大家AK杯 灰天飞雁NOIP模拟赛题解/数据/标程

    数据 http://files.cnblogs.com/htfy/data.zip 简要题解 桌球碰撞 纯模拟,注意一开始就在袋口和v=0的情况.v和坐标可以是小数.为保险起见最好用extended/ ...

  5. 队爷的讲学计划 CH Round #59 - OrzCC杯NOIP模拟赛day1

    题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的讲学计划 题解:刚开始理解题意理解了好半天,然后发 ...

  6. 队爷的Au Plan CH Round #59 - OrzCC杯NOIP模拟赛day1

    题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的Au%20Plan 题解:看了题之后觉得肯定是DP ...

  7. 队爷的新书 CH Round #59 - OrzCC杯NOIP模拟赛day1

    题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的新书 题解:看到这题就想到了 poetize 的封 ...

  8. CH Round #58 - OrzCC杯noip模拟赛day2

    A:颜色问题 题目:http://ch.ezoj.tk/contest/CH%20Round%20%2358%20-%20OrzCC杯noip模拟赛day2/颜色问题 题解:算一下每个仆人到它的目的地 ...

  9. CH Round #52 - Thinking Bear #1 (NOIP模拟赛)

    A.拆地毯 题目:http://www.contesthunter.org/contest/CH%20Round%20%2352%20-%20Thinking%20Bear%20%231%20(NOI ...

随机推荐

  1. mysql 语句优化心得

    排序导致性能较慢 优化策略:1.尽量不使用排序 2.只查有索引的结果然后 内连接查询 select  bizchance0_.*  from biz_chance bizchance0_, biz_b ...

  2. Android 网络图片Url 转 Bitmap

    注意:该方法必须要在子线程中调用,因为涉及网络请求 public Bitmap getBitmap(String url) { Bitmap bm = null; try { URL iconUrl ...

  3. Swiper+ ejs模板引擎+ iScroll插件知识总结

    一. Swiper swiper是一个应用于移动端的动画插件,原理类似于轮播图 官网 http://www.swiper.com.cn/# html结构 <div class="swi ...

  4. 洛谷—— P1018 乘积最大

    https://www.luogu.org/problem/show?pid=1018#sub 题目描述 今年是国际数学联盟确定的“2000――世界数学年”,又恰逢我国著名数学家华罗庚先生诞辰90周年 ...

  5. C#游戏开发高速入门 2.1 构建游戏场景

    C#游戏开发高速入门 2.1  构建游戏场景 假设已经计划好了要编写什么样的游戏,在打开Unity以后.要做的第一件事情就是构建游戏场景(Scene).游戏场景就是玩家游戏时,在游戏视图中看到的一切. ...

  6. [D3] Margin Convention with D3 v4

    You can’t add axes to a chart if you don’t make room for them. To that end, the D3 community has ado ...

  7. Linux下的lds链接脚本简介(二)

    七. SECTIONS命令 SECTIONS命令告诉ld如何把输入文件的sections映射到输出文件的各个section: 如何将输入section合为输出section; 如何把输出section ...

  8. [Algorithms] Binary Search Algorithm using TypeScript

    (binary search trees) which form the basis of modern databases and immutable data structures. Binary ...

  9. Android中Activity切换时共享视图元素的切换动画(5.0以上)

    同一时候公布在我的博客 点此进入 背景 说来这个的背景很easy,常常在使用图片列表的时候就会想,假设"列表中的图片放大到整个屏幕"作为 Activity 的补间动画.就很完美了. ...

  10. APK瘦身记,怎样实现高达53%的压缩效果

    作者:非戈@阿里移动安全,很多其它技术干货.请訪问阿里聚安全博客 1.我是怎么思考这件事情的 APK是Android系统安装包的文件格式.关于这个话题事实上是一个老生常谈的题目.不论是公司内部.还是外 ...