【Codeforces Round 345 (Div 1) B】【暴力 双指针】Image Preview 看照片、阅读、移动、反转最多看照片数
来源:互联网 发布:js mousewheel scroll 编辑:程序博客网 时间:2024/06/11 19:56
There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while passing all pictures from first to last? In other words, we are allowed to rearrange elements of a in any order. What is the maximum possible number of indices i (1 ≤ i ≤ n - 1), such that ai + 1 > ai.
The first line of the input contains integer n (1 ≤ n ≤ 1000) — the number of painting.
The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ 1000), where ai means the beauty of the i-th painting.
Print one integer — the maximum possible number of neighbouring pairs, such that ai + 1 > ai, after the optimal rearrangement.
520 30 10 50 40
4
4200 100 100 200
2
In the first sample, the optimal order is: 10, 20, 30, 40, 50.
In the second sample, the optimal order is: 100, 200, 100, 200.
#include<stdio.h>#include<iostream>#include<string.h>#include<string>#include<ctype.h>#include<math.h>#include<set>#include<map>#include<vector>#include<queue>#include<bitset>#include<algorithm>#include<time.h>using namespace std;void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }#define MS(x,y) memset(x,y,sizeof(x))#define MC(x,y) memcpy(x,y,sizeof(x))#define MP(x,y) make_pair(x,y)#define ls o<<1#define rs o<<1|1typedef long long LL;typedef unsigned long long UL;typedef unsigned int UI;template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b>a)a = b; }template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b<a)a = b; }const int N = 1e6 + 10, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;int n;int a, b, T;char s[N], t[N];int ss[N], tt[N];int ans;void solve(){int l = n - 1;for (int i = 0; i < n; ++i){int rst = T - ss[i];if (rst < 0)return;rst -= i*a;while (l >= 1 && tt[l] > rst)--l;gmax(ans, l + i);}}int main(){while (~scanf("%d%d%d%d", &n, &a, &b, &T)){scanf("%s", s);strcpy(t, s);reverse(t + 1, t + n);for (int i = 1; i < n; ++i){ss[i] = ss[i - 1] + a + 1 + (s[i] == 'w')*b;tt[i] = tt[i - 1] + a + 1 + (t[i] == 'w')*b;}T -= 1 + (s[0] == 'w')*b;if (T < 0){ puts("0"); continue; }ans = 0;solve();swap(ss, tt); solve();printf("%d\n", min(ans + 1, n));}return 0;}/*【trick&&吐槽】1,5e5的算法怎么做?大暴力!2,心态稳住,读题一定要读进去。不要明明在分心还强行读题。会让自己做得一塌糊涂。3,Phone is in the vertical orientation and can't be rotatedPhone!Phone!而不是picture。读题要读主语啊!4,LL可以用%d读入一个int,但是int不可以用%lld读入一个LL5,然而这题还是挂掉了,因为不一定是先向右后向左,还是有可能先向左后向右的。两者是不一样的,因为我们退回的距离存在差异。6,移动成本不要忘记*a【题意】有n张照片,形成一个环。现在看的照片是照片1。我们可以向左看或者向右看下一张照片。我们需要a的时间去移动到下一张照片上。需要1的时间去看一张没看过的照片需要b的时间去把照片翻转——照片为什么需要翻转呢?因为照片有垂直的和水平的,而手机是水平的且我们不能翻转手机。我们想要求出,在T秒内最多能看的照片数。【类型】暴力 双指针【分析】这道题我们发现,我们的解,一定是向右看了若干张,然后向左看了若干张。向右看的张数多了,自然向左看的张数就少了。于是我们直接暴力向右看了几张,这道题就做完了。= =然而要注意的是,先左后右和先右后左是不一样的。我们还要先左向右贪一波。【时间复杂度&&优化】O(n)【数据】Input10 2 3 32hhwwhwhwwh读1花1,移2花2,读2花1,移1花2,*/
- 【Codeforces Round 345 (Div 1) B】【暴力 双指针】Image Preview 看照片、阅读、移动、反转最多看照片数
- Codeforces Round #345 (Div. 2) D. Image Preview【二分】
- Codeforces Round #345 (Div. 2)D. Image Preview
- Codeforces Round #345 (Div. 2)D Image Preview
- Codeforces Round #345 (Div. 2)D Image Preview(二分)
- Codeforces Round #345 (Div. 2) D. Image Preview 前缀和
- 邀请别人看照片
- Codeforces Round #345 (Div. 2)(B)暴力
- Codeforces Round #345 (Div. 2)-B. Beautiful Paintings(暴力)
- Codeforces #345 div1 B. Image Preview 二分
- Codeforces Round #276 (Div. 1)B(暴力)
- Codeforces Round #313 (Div. 1) B. Equivalent Strings DFS暴力
- Codeforces Round #349 (Div. 1) B. World Tour (暴力搜索)
- Codeforces Round #336 (Div. 2) B 暴力
- Codeforces Round #309 (Div. 2) B 暴力
- Codeforces Round #363 (Div. 2) B 暴力
- 【Codeforces Round #410 (Div. 2) B】暴力
- Codeforces Round #345 (Div. 2) (D. Image Preview(二分))
- 【Codeforces Round 345 (Div 1) A】【STL-map or stable_sort or双关键字排序】Watchmen 曼哈顿距离=欧几里得距离点对数
- 一位一年android开发者的瓶颈
- c++ 一次读取文件全部内容
- 彻底理解js中this的指向
- js字符串操作总结
- 【Codeforces Round 345 (Div 1) B】【暴力 双指针】Image Preview 看照片、阅读、移动、反转最多看照片数
- XNA4.0 RPG游戏开发教程(五)
- 微信 昵称带 表情存入mysql数据库
- 关于drawInRect: withAttributes: 等新方法的使用
- sql学习-postgresql
- [转载]微服务实战(六):选择微服务部署策略
- 深入理解Arrays.sort()
- codeforces Problem- 630K Indivisibility
- Xilinx—Zynq架构介绍