Open hyponet opened 5 years ago
学生排队,顺时针或逆时针调整是否能连续,因为数据量少,所以采取不停左移然后判断是否有序
package main import ( "bufio" "fmt" "os" ) func isOrder(sts *[]int) bool { var g bool stsT := *sts if stsT[1] > stsT[0] { g = true } else { g = false } for i := 1; i < len(*sts); i += 1 { if g && stsT[i]-stsT[i-1] != 1 { return false } if !g && stsT[i-1]-stsT[i] != 1 { return false } } return true } func offset(sts *[]int) *[]int { stsT := *sts tmp := stsT[len(stsT)-1] for i := len(stsT) - 1; i > 0; i -= 1 { stsT[i] = stsT[i-1] } stsT[0] = tmp return &stsT } func main() { input := bufio.NewReader(os.Stdin) var ( total int n int ) _, _ = fmt.Fscan(input, &total) for t := 0; t < total; t += 1 { _, _ = fmt.Fscan(input, &n) sts := make([]int, n) for i := 0; i < n; i += 1 { _, _ = fmt.Fscan(input, &sts[i]) } if n < 2 { fmt.Println("YES") continue } isCW := false for i := 0; i < n; i += 1 { if isOrder(offset(&sts)) { isCW = true break } } if isCW { fmt.Println("YES") } else { fmt.Println("NO") } } }
给 4n 个边,问是否能构造 n 个面积一样的矩形,关键在于想清楚这个面积应该是最小边乘以最大边
package main import ( "bufio" "fmt" "os" "sort" ) func main() { input := bufio.NewReader(os.Stdin) var ( total int n int ) _, _ = fmt.Fscan(input, &total) for t := 0; t < total; t += 1 { _, _ = fmt.Fscan(input, &n) stick := make([]int, n*4) count := make(map[int]int) for i := 0; i < n*4; i += 1 { _, _ = fmt.Fscan(input, &stick[i]) count[stick[i]] += 1 } isFound := true hasErr := false newSide := make([]int, 0) for k, v := range count { if v%2 != 0 { hasErr = true break } c := v / 2 for i := 0; i < c; i++ { newSide = append(newSide, k) } } if hasErr { fmt.Println("NO") continue } sort.Ints(newSide) sum := newSide[0] * newSide[len(newSide)-1] for i, j := 0, len(newSide)-1; i < j; i, j = i+1, j-1 { if sum != newSide[i]*newSide[j] { isFound = false break } } if isFound { fmt.Println("YES") } else { fmt.Println("NO") } } }
A 题目
学生排队,顺时针或逆时针调整是否能连续,因为数据量少,所以采取不停左移然后判断是否有序
B 题
给 4n 个边,问是否能构造 n 个面积一样的矩形,关键在于想清楚这个面积应该是最小边乘以最大边