
水题
美丽的小黄人
这个作者很懒,什么都没留下…
展开
-
Java使用PriorityQueue优先队列实现大顶堆
leetcode 40.最小的k个数输入整数数组 arr ,找出其中最小的 k 个数。例如,输入4、5、1、6、2、7、3、8这8个数字,则最小的4个数字是1、2、3、4。示例 1:输入:arr = [3,2,1], k = 2输出:[1,2] 或者 [2,1]示例 2:输入:arr = [0,1,2,1], k = 1输出:[0]限制:0 <= k <= arr.length <= 100000 <= arr[i]<= 10000...原创 2020-07-31 16:27:42 · 1626 阅读 · 1 评论 -
java 实现类似C++结构体
P1563 玩具谜题:https://www.luogu.com.cn/problem/P1563import java.util.*;class Node{ String name = ""; int direction = 0; Node(int direction, String name){ this.name = name; ...原创 2020-03-06 14:09:30 · 945 阅读 · 0 评论 -
java重写sort()
这是一道洛谷的简单模拟P1056 排座椅:https://www.luogu.com.cn/problem/P1056import java.util.*;public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); ...原创 2020-03-06 14:07:33 · 1985 阅读 · 0 评论 -
回文数的判断(三种方法)
最近做了一点关于回文数的总结。 首先先写一篇关于回文数判断的几种方法。 回文数的概念:即是给定一个数,这个数顺读和逆读都是一样的。例如:121,1221是回文数,123,1231不是回文数。 方法一: 试用情境,处理小数字。使用数学方法。输入的回文数x的范围为x<10^9,int存储,或者x<10^18,long long存储的数,数字的范围不大。这里写的是int存储情...转载 2018-08-01 14:49:02 · 19463 阅读 · 0 评论 -
C++最简单的四舍五入!!(setprecision(n)方法)
setprecision(n)是流格式控制符之一,在iomanip头文件中。c++默认的流输出数值有效位是6,包括整数和小数,若数值超出6位,则第七位四舍五入到6位数fixed :浮点值显示为定点十进制。 默认是小数6位数,不包含整数,若小数位超出6位,则四舍五入到6位数1.setprecision(n) 指定一个浮点数的精度默认设置输出的数字的总位数为n,包含整数和小数部分;其中se...转载 2018-08-01 15:30:49 · 6270 阅读 · 1 评论 -
c++任意交换两个变量swap()
#include <iostream>using namespace std;int main(){ int a = 5, b = 2; swap(a, b); cout << a << b; return 0;}结果是 25原创 2018-08-01 15:45:19 · 1885 阅读 · 0 评论 -
整型数组正序、逆序输出(索引)(交叉排序)
import java.util.Arrays;import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(...原创 2018-09-04 18:38:54 · 1414 阅读 · 0 评论 -
用暴力求范围小的最大子阵
给定一个n*m的矩阵A, 求A中的一个非空子矩阵,使这个子矩阵中的元素和最大。 输入:输入的第一行包含两个整数n,m(1<=n, m<=50),分别表示矩阵A的行数和列数,接下来n行 每行m个整数,矩阵Aij(-1000<=Aij<=1000)。 样例输入: 3 3 2 -4 1 -1 2 1 4 -2 2 样例输出: 6代码:import ja...原创 2018-09-02 21:28:50 · 169 阅读 · 0 评论 -
中序遍历二叉树
题目描述给定一个二叉树,返回其中序遍历。例如: 给定二叉树 [1,null,2,3], 1 \ 2 / 3返回 [1,3,2].说明: 递归算法很简单,你可以通过迭代算法完成吗?/** * Definition for a binary tree node. * public class TreeNode { * in...转载 2018-11-06 18:49:55 · 249 阅读 · 0 评论 -
C. Alphabetic Removals
http://codeforces.com/contest/999/problem/C给n个字母,删掉k个, 从a开始删,删完了a再开始删b ,一直到z, 输出剩下的字符import java.util.Scanner;public class Main { public static void main(String[] args) throws Exception { ...原创 2018-06-28 18:42:16 · 312 阅读 · 0 评论 -
Codeforces Round #490 (Div. 3)
http://codeforces.com/contest/999/problem/Bimport java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.ArrayList;import java.util.List;//先找约数,反转相...原创 2018-06-24 21:36:09 · 172 阅读 · 0 评论 -
Codeforces #481(div3) B. File Name
B. File Nametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou can not just take the file and send it. When Polycarp trying to send a file in the ...原创 2018-06-13 17:54:20 · 821 阅读 · 0 评论 -
Codeforces#481(div3) A. Remove Duplicates
A. Remove DuplicatesPetya has an array aa consisting of nn integers. He wants to remove duplicate (equal) elements.Petya wants to leave only the rightmost entry (occurrence) for each element of the ar...原创 2018-06-13 17:46:01 · 387 阅读 · 0 评论 -
Codeforces#481(Div3) C. Letters
C. Letterstime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are nn dormitories in Berland State University, they are numbered with integers fr...原创 2018-06-13 17:41:38 · 553 阅读 · 0 评论 -
Codeforces #485 div2 B. High School: Become Human
B. High School: Become Humantime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYear 2118. Androids are in mass production for decades now, and they do...原创 2018-06-11 20:14:13 · 233 阅读 · 0 评论 -
Codeforces #485 div2 A. Infinity Gauntlet
A. Infinity Gauntlettime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a...原创 2018-06-11 20:11:08 · 219 阅读 · 0 评论 -
Codeforces #485 C. Three displays
C. Three displaystime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a ...原创 2018-06-11 20:05:39 · 163 阅读 · 0 评论 -
Codeforces #486 C - Equal Sums div3
You are given kk sequences of integers. The length of the ii-th sequence equals to nini.You have to choose exactly two sequences ii and jj (i≠ji≠j) such that you can remove exactly one element in each...原创 2018-06-08 19:10:39 · 270 阅读 · 0 评论 -
Codeforces #484(div2) B. Bus of Characters
http://codeforces.com/contest/982/problem/B题意:输入:有n排椅子(每排坐俩),每排椅子的宽带都不一样,第二行输入它们的宽度,然后假设有n个站台,每个站台会上两个人,人可以分为两类,第一类人是找空排坐,并且还找宽度最小的坐;第二类人找旁边有人的坐,并且在这基础上找宽度最大的坐。第三行输入2*n个人,0为第一类人,1为第二类人。输出:每个人分别坐...转载 2018-06-20 20:45:04 · 203 阅读 · 0 评论 -
Codeforces #479(div3) C. Less or Equal
C. Less or EqualYou are given a sequence of integers of length nn and integer number kk. You should print any integer number xx in the range of [1;109][1;109] (i.e. 1≤x≤1091≤x≤109) such that exactly k...原创 2018-06-19 10:58:19 · 227 阅读 · 0 评论