首页 > 其他 > 详细

kotlin笔记:copy from a man in integrity

时间:2020-05-27 23:50:47      阅读:78      评论:0      收藏:0      [点我收藏+]

https://codeforces.com/contest/1360/submission/81404262

import java.lang.IllegalArgumentException
import java.lang.StringBuilder
import java.sql.Array
import java.util.*;
import kotlin.Comparator

import kotlin.collections.ArrayList
import kotlin.math.*;
import kotlin.system.exitProcess
import  kotlin.collections.*

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readDouble() = readLn().toDouble() // single double
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map { it.toLong() } // list of longs
private fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles

class Bit(var n:Int) {
    var a = ArrayList<Long>()
    init {
        a.resize(n+1,0);
    }
    fun clear(m:Int) {
        n = m
        a.resize(n+1,0)
    }
    fun add(x:Int,v:Long) {
        var p = x
        while(p<=n) {
            a[p] += v
            p += p and -p
        }
    }
    fun sum(x:Int) : Long {
        var ans : Long = 0
        var p = x
        while(p>0) {
            ans += a[p]
            p -= p and -p
        }
        return ans
    }
}


fun lower_bound(a:ArrayList<Int>, l:Int, r:Int , x:Int ): Int {
    var L=l-1
    var R=r-1
    while(R-L>1) {
        var mid = (L+R)/2
        if(a[mid]>=x) R=mid
        else L=mid
    }
    return R
}

fun <T> ArrayList<T>.resize(n:Int, v:T) {
    this.clear()
    for(i in 0..n-1) this.add(v)
}

/*
---------------c++->kotlin-------------------
swap(a,b)                    a=b.also{b=a}
for(i=0;i<n;i++)             for(i in 0 until n) / for(i in 0..n-1)
for(i=n-1;i>=0;i--)          for(i in n-1 downTo 0)
for(auto it:s)               for(it in s)
min,max                      minOf,maxOf
printf                       println("${ans}")
println(res)                 println(res.joinToString(" "))
ll a[n]                      var a=Array<Long>(n){}
a&b                          a and b
a|b                          a or b
a^b                          a xor b
int gao(int a,int b)         fun gao(a:Int,b:Int):Int
---------sort---------
res.sortBy({it.fi})//res.sortByDescending({it.fi})
res.sortWith({it.fi},{it.se})//res.sortWith(compareByDescending { it.fi })
--------vector--------
vector<int> res;             var res=mutableListOf<Int>()
res.push_back                res.add
vector<int> mp[n];           var mp=Array(n){mutableListOf<Int>()}
---------set----------
set<int> s;                  var s=TreeSet<Int>()
s.insert                     s.add
s.erase                      s.remove
s.begin                      s.first
s.rbegin                     s.last
set<pair<int,int>> s;        var s=TreeSet<Pair<Int,Int>>(compareBy({it.first},{it.second}))
-----unordered_map-----
unordered_map<int,int>       var mp:MutableMap<Int,Int> = mutableMapOf()
mp[x]++                      mp[x]=(mp[x]?:0)+1
sum+=mp[x]                   sum+=mp[x]?:0
-----priority_queue-----
struct node{int a;}          data class node(var a:Int)
priority_queue<node> q;      var q=PriorityQueue<node>(compareBy({it.a}))
q.top                        q.peek
q.pop                        q.poll
q.push                       q.add
---------------------------------------------
 */

//---------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------

class node(val L:Int, val R:Int) {
    var Len = R-L+1
    private val myCustomComparator =  Comparator<node> { a, b ->
        when {
            (a == null && b == null) -> 0
            (a == null) -> -1
            else -> 1
        }
    }
}


fun get_factor(n:Int,k:Int):ArrayList<Int> {
    var ans = ArrayList<Int>()
    var i = 2
    while(i*i<=n) {
        if(n%i==0) {
            if(i<=k) ans.add(i)
            if(n/i<=k) ans.add(n/i)
        }
        i++
    }
    return  ans
}


fun main () {
    val T = readInt()
    repeat(T) {
        var n = readInt()
        var dp = ArrayList<ArrayList<Int>>()

        for (i in 1..n) {
            var line = ArrayList<Int>()
            line.resize(n, 0)
            dp.add(line)
        }

        var G = ArrayList<String>()
        for (i in 0..n - 1) {
            var temps = readLine()!!
            G.add(temps)
        }
        for (i in 0..n - 1) {
            if (G[n - 1][i] == ‘1‘) dp[n - 1][i] = 1
            if (G[i][n - 1] == ‘1‘) dp[i][n - 1] = 1
        }
        var flag = 1
        for(i in n-2 downTo 0) {
            for(j in n-2 downTo 0) {
                if(G[i][j]==‘1‘) {
                    if(dp[i+1][j]==0&&dp[i][j+1]==0) {
                        flag = 0
                        break
                    }
                    dp[i][j] = 1
                }
            }
            if(flag==0) break
        }
        if(flag==1) println("YES")
        else println("NO")
    }
}


kotlin笔记:copy from a man in integrity

原文:https://www.cnblogs.com/reshuffle/p/12977503.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!