Skip to main content
  1. Posts/

uva 6692 Lucky Number

·1 min
Note: This article is available in Chinese only. 本文暂无英文版本。 View original

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid;=8&page;=show_problem&problem;=4704

题目大意是说,定义一个数的lucky number是距离i最远的j且满足(a[i]<a[j] i<j)。

问对所有数最大的lucky number是什么。

不必线段树。

我们可以先处理出a[i]的最远点。倒着扫一遍即可。

然后可以处理出大于等于a[i]的最远位置。

 1/*************************************************************************
 2	> File Name: code/hust/20151115/A.cpp
 3	> Author: 111qqz
 4	> Email: rkz2013@126.com
 5	> Created Time: 2015年11月23日 星期一 22时13分15秒
 6 ************************************************************************/
 7
 8#include<iostream>
 9#include<iomanip>
10#include<cstdio>
11#include<algorithm>
12#include<cmath>
13#include<cstring>
14#include<string>
15#include<map>
16#include<set>
17#include<queue>
18#include<vector>
19#include<stack>
20#include<cctype>
21#define fst first
22#define sec second
23#define lson l,m,rt<<1
24#define rson m+1,r,rt<<1|1
25#define ms(a,x) memset(a,x,sizeof(a))
26using namespace std;
27const double eps = 1E-8;
28const int dx4[4]={1,0,0,-1};
29const int dy4[4]={0,-1,1,0};
30const int N=1E5+6;
31typedef long long LL;
32int a[N];
33int n;
34int p[N];
35const int inf = 0x3f3f3f3f;
36int main()
37{
38  #ifndef  ONLINE_JUDGE
39   freopen("in.txt","r",stdin);
40  #endif
41
42   int T;
43   scanf("%d",&T);
44   while (T--)
45   {
46       scanf("%d",&n);
47       int mx = -1;
48       for ( int i = 1 ; i <= n ; i++ ) scanf("%d",&a[i]),mx = max(mx,a[i]);
49
50
51       ms(p,-1);
52       for ( int i  = 1 ; i <= n ; i++)
53	   p[a[i]] = max(p[a[i]],i);   //最远的a[i]的位置
54       for ( int i = mx ; i >= 1 ; i--)
55	   p[i] = max(p[i],p[i+1]);//cout<<"p[i]:"<<p[i]<<endl; //最远的>= a[i]的位置
56
57	int ans =  0;
58	for ( int i = 1 ; i <= n ; i++)
59	    ans = max(ans,p[a[i]+1]-i);
60       printf("%d\n",ans);
61
62   }
63
64
65
66
67 #ifndef ONLINE_JUDGE
68  #endif
69  fclose(stdin);
70	return 0;
71}

Related

poj 2159 Ancient Cipher(水)

·1 min
由于顺序是可以改变的. 所以考虑是否可以映射.只要存在字母对应出现的次数都相同.那么就可以通过映射得到. 具体是开一个数组记录每个字母出现的次数… 然后sort

codeforces #317 div2 A. Arrays (水)

·1 min
应该3分钟过的题。。。 结果花了8分钟。。。ssssad 1/************************************************************************* 2 > File Name: code/cf/#317/A.cpp 3 > Author: 111qqz 4 > Email: rkz2013@126.com 5 > Created Time: 2015年08月23日 星期日 00时29分47秒 6 ************************************************************************/ 7 8#include<iostream> 9#include<iomanip> 10#include<cstdio> 11#include<algorithm> 12#include<cmath> 13#include<cstring> 14#include<string> 15#include<map> 16#include<set> 17#include<queue> 18#include<vector> 19#include<stack> 20#include<cctype> 21#define y1 hust111qqz 22#define yn hez111qqz 23#define j1 cute111qqz 24#define ms(a,x) memset(a,x,sizeof(a)) 25#define lr dying111qqz 26using namespace std; 27#define For(i, n) for (int i=0;i<int(n);++i) 28typedef long long LL; 29typedef double DB; 30const int inf = 0x3f3f3f3f; 31const int N=1E5+7; 32int na,nb,k,m; 33int a[N],b[N]; 34int main() 35{ 36 #ifndef ONLINE_JUDGE 37 freopen("in.txt","r",stdin); 38 #endif 39 cin>>na>>nb; 40 cin>>k>>m; 41 for ( int i = 1 ; i <= na ; i++){ 42 scanf("%d",&a[i]); 43 } 44 for ( int i = 1 ; i<= nb ; i++){ 45 scanf("%d",&b[i]); 46 } 47 if (a[k]<b[nb-m+1]){ 48 puts("YES"); 49 } 50 else 51 { 52 puts("NO"); 53 } 54 55 56 #ifndef ONLINE_JUDGE 57 fclose(stdin); 58 #endif 59 return 0; 60}

codeforces #332 div 2 C. Day at the Beach

·2 mins
C. Day at the Beach time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output One day Squidward, Spongebob and Patrick decided to go to the beach. Unfortunately, the weather was bad, so the friends were unable to ride waves. However, they decided to spent their time building sand castles.

codeforces #332 div 2 B. Spongebob and Joke

·2 mins
B. Spongebob and Joke time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output While Patrick was gone shopping, Spongebob decided to play a little trick on his friend. The naughty Sponge browsed through Patrick’s personal stuff and found a sequence _a_1, _a_2, …, a__m of length m, consisting of integers from 1 to n, not necessarily distinct. Then he picked some sequence _f_1, _f_2, …, f__n of length n and for each number a__i got number b__i = f__a__i. To finish the prank he erased the initial sequence a__i.

codeforces #332 div 2 A. Patrick and Shopping

·2 mins
1#include <cstdio> 2#include <iostream> 3#include <cmath> 4using namespace std; 5long long d1,d2,d3; 6int main() 7{ 8cin>>d1>>d2>>d3; 9long long ans = 999999999999; 10ans = min(ans,d1+d2+d3); 11ans = min (ans,d1*2+d2*2); 12ans = min (ans,d1*2+2*d3); 13ans = min(ans,d2*2+2*d3); 14cout<<ans<<endl; 15return 0; 16} time limit per test 1 second