题意:给定 n 个数,让你修改最少的数,使得这是一个不下降序列。

析:和3670一思路,就是一个LIS,也可以直接暴力,因为只有两个数,所以可以枚举在哪分界,左边是1,右边是2,更新答案。

代码如下:

#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
using namespace std ; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f3f;
const double eps = 1e-8;
const int maxn = 3e4 + 5;
const int dr[] = {0, 0, -1, 1};
const int dc[] = {-1, 1, 0, 0};
int m, n;
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
int a[maxn], b[maxn]; int solve(){
fill(b, b+n, INF);
for(int i = 0; i < n; ++i)
*upper_bound(b, b+n, a[i]) = a[i];
return lower_bound(b, b+n, INF) - b;
} int main(){
while(scanf("%d", &n) == 1){
for(int i = 0; i < n; ++i) scanf("%d", &a[i]);
int ans = n - solve();
printf("%d\n", ans);
}
return 0;
}
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
using namespace std ; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f3f;
const double eps = 1e-8;
const int maxn = 30000 + 5;
const int dr[] = {0, 0, -1, 1};
const int dc[] = {-1, 1, 0, 0};
int m, n;
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
int a[maxn]; int main(){
while(scanf("%d", &n) == 1){
int cnt1 = 0, cnt2 = 0;
for(int i = 0; i < n; ++i){
scanf("%d", &a[i]);
if(a[i] == 1) ++cnt1;
else ++cnt2;
}
int ans = INF;
int cnt11 = 0, cnt22 = 0; for(int i = 0; i < n; ++i){
ans = min(ans, cnt22 + cnt1-cnt11);
if(a[i] == 1) ++cnt11;
else ++cnt22;
}
ans = min(ans, cnt22 + cnt1-cnt11);
ans = min(ans, cnt1);
ans = min(ans, cnt2);
printf("%d\n", ans);
}
return 0;
}

POJ 3671 Dining Cows (DP,LIS, 暴力)的更多相关文章

  1. poj 3671 Dining Cows (Dp)

    /* 一开始并没有想出On的正解 后来发现题解的思路也是十分的巧妙的 还是没能把握住题目的 只有1 2这两个数的条件 dp还带练练啊 ... */ #include<iostream> # ...

  2. F-Dining Cows(POJ 3671)

    Dining Cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7584   Accepted: 3201 Descr ...

  3. Codeforces.264E.Roadside Trees(线段树 DP LIS)

    题目链接 \(Description\) \(Solution\) 还是看代码好理解吧. 为了方便,我们将x坐标左右反转,再将所有高度取反,这样依然是维护从左到右的LIS,但是每次是在右边删除元素. ...

  4. POJ 3281 Dining (网络流)

    POJ 3281 Dining (网络流) Description Cows are such finicky eaters. Each cow has a preference for certai ...

  5. tarjan缩点练习 洛谷P3387 【模板】缩点+poj 2186 Popular Cows

    缩点练习 洛谷 P3387 [模板]缩点 缩点 解题思路: 都说是模板了...先缩点把有环图转换成DAG 然后拓扑排序即可 #include <bits/stdc++.h> using n ...

  6. hdu----(1677)Nested Dolls(DP/LIS(二维))

    Nested Dolls Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  7. poj3671Dining Cows(DP)

    主题链接: 啊哈哈,点我点我 题意: 给一个仅仅含有1.2的序列,如何变换n次使序列成为一个非递减的序列,而且使n最小. 思路: 这道题的数据范围是50000,则肯定承受不了n方的复杂度.所以 仅仅能 ...

  8. poj 2456 Aggressive cows && nyoj 疯牛 最大化最小值 二分

    poj 2456 Aggressive cows && nyoj 疯牛 最大化最小值 二分 题目链接: nyoj : http://acm.nyist.net/JudgeOnline/ ...

  9. POJ 2456 Agressive cows(二分)

    POJ 2456 Agressive cows 农夫 John 建造了一座很长的畜栏,它包括N (2≤N≤100,000)个隔间,这 些小隔间的位置为x0,...,xN-1 (0≤xi≤1,000,0 ...

随机推荐

  1. bzoj2085

    首先看到k的范围就该知道这题不是倍增就是矩乘 首先肯定要求出任意一对串(a,b) a的后缀与b的前缀相同的最长长度是多少 考虑到kmp求出的失配指针是一个串最长后缀和前缀相等的长度 这里多个串我们只要 ...

  2. uva10375 Choose and divide

    唯一分解定理. 挨个记录下每个质数的指数. #include<cstdio> #include<algorithm> #include<cstring> #incl ...

  3. LA 3263 (平面图的欧拉定理) That Nice Euler Circuit

    题意: 平面上有n个端点的一笔画,最后一个端点与第一个端点重合,即所给图案是闭合曲线.求这些线段将平面分成多少部分. 分析: 平面图中欧拉定理:设平面的顶点数.边数和面数分别为V.E和F.则 V+F- ...

  4. iDSDT搞定显卡和声卡 黑苹果不纠结

    原帖:http://www.lovelucy.info/idsdt-mac-video-audio-drive.html 之前写过PC机上装Mac OS X系统,准备工作中最纠结的就是驱动了.在网络上 ...

  5. OK335xS 网络连接打印信息 hacking

    /*********************************************************************** * OK335xS 网络连接打印信息 hacking ...

  6. django - 好的 获取 参数值 方法

    第一步: # 参数列表 parameters = ('user_id', 'day_time', 'normal_data', 'hourly_data', 'product_id') # 需要传入的 ...

  7. tomcat 调优

    1 总是遇到read time out ,socket什么的           <Executor name="tomcatThreadPool" namePrefix=& ...

  8. andeoid学习笔记七

    Android中Broadcast的Intent大全 Api Level 3:(SDK 1.5) android.bluetooth.a2dp.intent.action.SINK_STATE_CHA ...

  9. hdu 4081 Qin Shi Huang's National Road System(最小生成树+dp)2011 Asia Beijing Regional Contest

    同样是看别人题解才明白的 题目大意—— 话说秦始皇统一六国之后,打算修路.他要用n-1条路,将n个城市连接起来,并且使这n-1条路的距离之和最短.最小生成树是不是?不对,还有呢.接着,一个自称徐福的游 ...

  10. xp重装系统后恢复Linux启动

    我的电脑----右键-----属性----高级----启动与恢复故障----设置编辑 [boot loader]timeout=3default=multi(0)disk(0)rdisk(0)part ...