【2019年蓝桥杯省赛A组】【简单记录】【自己用】

1.int型变String型

 String s=String.valueOf(i);
A题:sum必须要用long型,如果用int会溢出,打印出的是-1636549443
B题:由与题目的要求我们只需求得最后四位,所以模10000即可 不模的话很快就会溢出 

3.类的使用

class shop
{
	int time[];
	public shop (int t)
	{
		time=new int [t+1];
	}
}
//.....
		for(int i=0;i<n;i++) {
			s[i]=new shop(t);
		}
		for(int i=0;i<m;i++)
		{
			temp=in.nextInt();
			sh=in.nextInt();
			s[sh-1].time[temp]++;
		}

3.读取一行字符

  for (int i = 0; i < n; i++) {
        String line = in.nextLine();
        mapp[i] = line.toCharArray();
    }

4.定义比较长的变量,用long或者double,再不行就用BigInteger

5.计算程序运行时间

long startTime = System.currentTimeMillis();    //获取开始时间
...
long endTime = System.currentTimeMillis();    //获取结束时间
System.out.println("程序运行时间:" + (endTime - startTime) + "ms");    //输出程序运行时间

6.dfs 当前有 /当前没有

package 题目;

import java.util.ArrayList;
import java.util.List;

public class _求幂集 {

	public static void main(String[] args) {
        List<List<Integer>> list=new ArrayList<List<Integer>>();  //注意这个初始化
		int a[]=new int[]{1,2,3};
		dfs(list,new ArrayList(),a,0);
		System.out.print(list);

	}
	public static void dfs(List<List<Integer>> res,List<Integer> now,int a[],int i)
	{
		if(i>=a.length)
		{
			res.add(new ArrayList(now));
			return;
		}
		now.add(a[i]);
		dfs( res , now,a, i+1);
		now.remove(now.size()-1);
		dfs(res,now,a,i+1);
	}
}

7 . switch +dfs

static boolean dfs(int x, int y) {
		if (x < 0 || x >= 10 || y < 0 || y >= 10)
			return true;
		if (vis[x][y]) 
			return false;
		
		vis[x][y] = true;
		switch (mp[x][y]) {
			case 'L':
				return dfs(x, y - 1);
			case 'R':
				return dfs(x, y + 1);
			case 'U':
				return dfs(x - 1, y);
			case 'D':
				return dfs(x + 1, y);
		}
		
		return false;
	}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值