自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(15)
  • 收藏
  • 关注

原创 单调递增最长子序列

解法:动态规划#include <iostream>#include<bits/stdc++.h>using namespace std;#define MAX 10001int main(){ int a[MAX]; int n; cin >> n; int dp[n+1]; dp[0] = 1; for(int i = 0;i < n;i++){ cin >> a[i].

2020-08-31 16:53:35 69

原创 最大子段和问题——动态规划

#include <iostream>#include <bits/stdc++.h>using namespace std;#define MAX 1001int a[MAX];int main(){ int n; cin >> n; for(int i = 1;i <= n;i++){ cin >> a[i]; } int dp[n+1]; int res = 0; ..

2020-08-30 03:09:31 94

原创 排列问题

#include <iostream>#include <bits/stdc++.h>using namespace std;void swap(int &a , int &b){ int temp; temp = a; a = b; b = temp; }void Perm(int list[], int k, int m){ if(k == m){ for(int i = 0;i <= m;i++) .

2020-08-29 00:23:38 82

原创 2017蓝桥杯Java A——迷宫

问题描述:X星球的一处迷宫游乐场建在某个小山坡上。它是由10x10相互连通的小房间组成的。房间的地板上写着一个很大的字母。我们假设玩家是面朝上坡的方向站立,则:L表示走到左边的房间,R表示走到右边的房间,U表示走到上坡方向的房间,D表示走到下坡方向的房间。X星球的居民有点懒,不愿意费力思考。他们更喜欢玩运气类的游戏。这个游戏也是如此!开始的时候,直升机把100名玩家放入一个个小房间内。玩家一定要按照地上的字母移动。迷宫地图如下:UDDLUULRULUURLLLRRRURRUURLDLRD

2020-08-17 16:07:52 281

原创 出现k次与出现1次

解法1;HashMappublic static int getOnce2(int[] nums) { Map<Integer, Integer> map = new HashMap<Integer, Integer>(); for (int i = 0; i < nums.length; i++) { if(map.containsKey(nums[i])) { int num = map.get(nums[i]); num++; map.pu.

2020-08-12 21:42:35 109

原创 0~1之间浮点实数的二进制表示(Java)

import java.util.*;public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); double n = sc.nextDouble(); sc.close(); StringBuilder sb = new StringBuilder("0."); while(n > 0) { double r = 2 * n; .

2020-08-12 20:44:07 248

原创 将整数的奇偶位调换(Java)

import java.util.*;public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); sc.close(); int ou = n & 0xaaaaaaaa; //和1010 1010 ....(32位)做&运算取出偶数位 int ji = n & 0x55555

2020-08-12 20:12:32 351

原创 是不是2的整数次方(Java)

思路:一个数是2的整数次方,意味着这个数用二进制表示是里面只有一个数字是1,我们仍然采用位运算import java.util.*;public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); sc.close(); if(((n-1)&n)==0) { System.out.printl.

2020-08-12 16:59:28 233

原创 二进制中1的个数

import java.util.*;public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); sc.close(); int ans = 0; while(n!=0) { n = n & (n-1); ans++; } System.out.println(ans);.

2020-08-12 16:51:17 83

原创 找出落单的那个数(Java)

算法思路:异或运算import java.util.*;public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] arr = new int[n]; sc.nextLine(); for(int i = 0;i < n;i++) { arr[i] = sc.nextInt(.

2020-08-12 16:39:26 308

原创 如何找数组中唯一成对的那个数?

思路: 异或运算解法一:import java.util.*;public class Main{ public static void main(String[] args) { int N = 1001; int[] arr = new int[N]; for(int i = 0;i < N;i++) { arr[i] = i+1; } arr[N-1] = new Random().nextInt(N-1)+1; int index = new Ra.

2020-08-12 16:28:11 144

原创 位运算的奇技淫巧

1.判断一个数x的奇偶性:x & 1 = 1 //x为奇数x & 1 = 0 //x为偶数2.n个数(1~n)放入n+1的空间中,其中一个数重复,求这个重复的数原理:异或运算(相同为0,不同为1)3.输入一个数,输出该数的二进制表示时1的个数while(n){ n = n & (n-1); ans++;}4.将十进制的数转化为二进制...

2020-08-11 21:50:40 74

原创 素数的个数(Java)

埃氏筛法import java.util.*;public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); sc.close(); int[] prime = new int[1000001]; boolean[] is_prime = new boolean[100000002]; int ..

2020-08-03 11:27:42 841

原创 判断素数(Java)

import java.util.*;public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); sc.close(); if(isPrime(n)== true) { System.out.println("YES"); } else { System.out.println("NO.

2020-08-03 11:04:14 1076

原创 线段上格点的个数(Java)

辗转相除法,答案就是gcd(abs(x1-x2),abs(y1-y2))-1,为什么可以这样做呢? 仔细想想,求出最大公约数g,也就是把y分为g个部分组成,x也是g个部分组成,这样的话,从起点开始,每次横坐标和纵坐标分别增加相应的一部分,一直增到终点,这个过程就是模拟的过程import java.util.*;public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(Syste.

2020-08-03 10:53:25 223

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除