結果

問題 No.750 Frac #1
ユーザー fmhr
提出日時 2018-11-09 21:41:35
言語 Go
(1.23.4)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,737 bytes
コンパイル時間 12,281 ms
コンパイル使用メモリ 241,740 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-29 14:35:47
合計ジャッジ時間 13,532 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"sort"
	"strconv"
)

func main() {
	log.SetFlags(log.Lshortfile)
	n := nextInt()
	ps := make([]Pair, n)
	for i := 0; i < n; i++ {
		ps[i].a = nextInt()
		ps[i].b = nextInt()
	}
	sort.Sort(Pairs(ps))
	out := bufio.NewWriter(os.Stdout)
	for i := 0; i < n; i++ {
		log.Println(ps[i], float64(ps[i].a)/float64(ps[i].b))
		fmt.Fprintf(out, "%d %d\n", ps[i].a, ps[i].b)
	}
	out.Flush()
}
func Max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func Min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func Sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func Abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	return float64(p[i].a)/float64(p[i].b) > float64(p[j].a)/float64(p[j].b)
}

var nextReader func() string

func init() {
	nextReader = NewScanner()
}

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}
func nextString() string {
	return nextReader()
}
func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}
func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}
func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(nextReader(), 64)
	return f
}
0