UVA - 481 - What Goes Up

10 views
Skip to first unread message

mostafa S.M

unread,
Nov 20, 2009, 4:28:11 PM11/20/09
to aut-a...@googlegroups.com
salam...
in soal ye soale DPe va bayad roosh binary search bezanim inaro midunam amma mikham bedunam ke code man che moshkeli dare ke WA migiram...
algorithme man Greedy e va manteghanam bayad kamelan dorost bashe...
lotf konin age test case eshtebahi peyda kardin reply konin ta ye fekri barash bokonam...
Inam codam :
@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@
 
#include <iostream>
#include <algorithm>

using namespace std;

#define N 100000
#define inf 2147483647

int num[N] , arr[N];

int main()
{
 //freopen("what.in", "r", stdin);
 int cn = 0;
 //memset(num , 0 , sizeof num);
 while(cin >> num[cn++])
 {
  ;
 }
 int j = 0;
 fill(arr , arr+N , inf);
 for (int i = 0 ; i < cn -1 ; i++)
 {
  if(j == 0)
  {
  if(num[i] < arr[j])
  arr[j++] = num[i];
  }
  if(j == 1)
  {
  if(num[i] < arr[j-1])
  {
  arr[j-1] = num[i];
  continue;
  }
  if(num[i] < arr[j] && num[i] > arr[j-1])
  arr[j++] = num[i];
  }
  else
  {
  if(num[i] < arr[j-1] && num[i] > arr[j-2])
  {
  arr[j-1] = num[i];
  continue;
  }
  if(num[i] < arr[j] && num[i] > arr[j-1])
  arr[j++] = num[i];
  }
 }
 cout << j << endl << "-" << endl;
 for(int i = 0 ; i < j ;i++)
  cout << arr[i] << endl;

 return 0;
}

@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@
329.png

Pouria Alimirzaee

unread,
Nov 21, 2009, 2:44:30 AM11/21/09
to aut-a...@googlegroups.com
rahe hale shoma baraye in test eshtebah hast:

4 5 6 1 2 3 4



--

You received this message because you are subscribed to the Google Groups "AUT-ACMICPC" group.
To post to this group, send email to aut-a...@googlegroups.com.
To unsubscribe from this group, send email to aut-acmicpc...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/aut-acmicpc?hl=.

329.png

mostafa S.M

unread,
Nov 21, 2009, 3:25:37 PM11/21/09
to aut-a...@googlegroups.com
thanks...

Reply all
Reply to author
Forward
0 new messages