TAILIEUCHUNG - Algorithms for programmers phần 8

Một chuỗi đúng giọng đều đều là một chuỗi giọng đều đều mà không có cặp giống hệt nhau của các yếu tố. Xét nghiệm này hóa ra là hơi dễ dàng hơn: mẫu int is_strictly_monotone (const Loại * f, ULONG n) / / trả lại / / 1 cho đúng thứ tự tăng dần / / -1 cho đúng thứ tự giảm dần / / khác 0 | CHAPTER 9. SORTING AND SEARCHING 149 if k n return 1 constant is considered ascending here int s f k f k-1 1 -1 if s 0 was ascending scan for descending pair for k n k if f k f k-1 return 0 else was descending 5 scan for ascending pair for k n k if f k f k-1 return 0 return s A strictly monotone sequence is a monotone sequence that has no identical pairs of elements. The test turns out to be slightly easier template typename Type int is_strictly_monotone const Type f ulong n return 1 for strictly ascending order -1 for strictly descending order else 0 if 1 n return 1 ulong k 1 if f k f k-1 return 0 int s f k f k-1 1 -1 if s 0 was ascending scan for descending pair for k n k if f k f k-1 return 0 else was descending 5 scan for ascending pair for k n k if f k f k-1 return 0 return s FXT file sort A sequence is called convex if it starts with an ascending part and ends with a descending part. A concave sequence starts with a descending and ends with an ascending part. Whether a monotone sequence is considered convex or concave again is a matter of convention . you have the choice to consider the first or the last element as extremum . Lacking a term that contains both convex and concave the following routine is called is_convex template typename Type long is_convex Type f ulong n return val for convex sequence first rising then falling -val for concave sequence first falling then rising else 0 val is the second index of the first pair at the point where the ordering changes val n iff seq. is monotone. note a constant sequence is considered any of rising falling if 1 n return 1 ulong k 1 for k 1 k n k skip constant start CHAPTER 9. SORTING AND SEARCHING 150 if f k f k-1 break if k n return n constant is considered convex here int s f k f k-1 1 -1 if s 0 was ascending scan for strictly descending pair for k n k if f k f k-1 break s k else was descending scan for strictly ascending pair for k n k if f k f k-1 break s -k if k n return s sequence is monotone

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.