import java.util.*;
public class Simple {
public static int randi(int start)
{
return (int) (Math.random() * start);
}
public static int[] randi(int start, int length)
{
int[] rst = new int[length];
for (int i = 0; i < length; i++)
{
rst[i] = randi(start);
}
return rst;
}
public static void p(int[] arr)
{
for (int v: arr)
{
System.out.print(v + " ");
}
System.out.print("\n"); // 'a' char type
// "s" string s
}
public static void bubbleSort(int[] arr)
{
for (int i = arr.length - 1; i > 0; i--)
{
for (int j = 0; j < i; j++)
{
if (arr[j] > arr[j+1])
{
swap(arr, j, j+1);
}
}
p(arr);
}
}
public static int smallestIndex(int[] arr, int start)
{
int min = arr[start];
int minIndex = start;
for (int i = start; i < arr.length; i++)
{
if (arr[i] < min)
{
min = arr[i];
minIndex = i;
}
}
return minIndex;
}
public static int[] bubbleSortNew(int[] arr)
{
int[] rst = new int[arr.length];
for (int i = 0; i < arr.length; i++)
{
rst[i] = arr[i];
}
for (int i = rst.length - 1; i > 0; i--)
{
for (int j = 0; j < i; j++)
{
if (rst[j] > rst[j+1])
{
swap(rst, j, j+1);
}
}
p(rst);
}
return rst;
}
public static void swap(int[] arr, int i, int j)
{
int tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
}
public static void selectSort(int[] arr)
{
for (int i = 0; i < arr.length; i++)
{
// int minIndex = smallestIndex(arr, i);
int minIndex = i;
for (int j = i; j < arr.length; j++)
{
if (arr[j] < arr[minIndex])
{
minIndex = j;
}
}
// swap(arr, i, minIndex);
int tmp = arr[i];
arr[i] = arr[minIndex];
arr[minIndex] = tmp;
}
}
public static void selectSort2(int[] arr)
{
for (int i = 0; i < arr.length; i++)
{
int minIndex = smallestIndex(arr, i);
swap(arr, i, minIndex);
}
}
public static void insertSort(int[] a)
{
int tmp = 0, j = 0;
for (int i = 0; i < a.length; i++)
{
tmp = a[i];
j = i - 1;
while (j >= 0 && tmp < a[j])
{
a[j+1] = a[j];
j--;
}
a[j+1] = tmp;
}
// p(a);
}
public static int find(int[] arr, int value)
{
for (int i = 0; i < arr.length; i++)
{
if (arr[i] == value)
{
return i;
}
}
return -1;
}
public static int find(ArrayList<String> list, String s)
{
for (int i = 0; i < list.size(); i++)
{
if(list.get(i).equals(s))
{
return i;
}
}
return -1;
}
public static int find(String source, String sub)
{
for (int i = 0; i <= source.length() - sub.length(); i++)
{
if(source.substring(i, i+sub.length()).equals(sub))
{
return i;
}
}
return -1;
}
public static int binarySearch(int[] nums, int v)
{
int low = 0, mid = 0;
int high = nums.length - 1;
while(low <= high)
{
mid = (low + high) / 2;
if(nums[mid] > v)
{
high = mid - 1;
}
else if(nums[mid] < v)
{
low = mid + 1;
}
else
{
return mid;
}
}
return -1;
}
public static void main(String[] args)
{
// System.out.println(find("hello", "l0"));
int[] nums = {75, 39, 39, 73, 51, 60, 65, 84};
bubbleSort(nums);
// p(nums);
System.out.println(binarySearch(nums, 51) + "sadfas");
}
}
摘要:
如何用post的方法以application/octet-stream的content-type提交json和文件呢,总是说文件类型错误 写入图片 该接口用于根据 spreadsheetToken 和 range 向单个格子写入图片。 请求方式 :POST 请求地址 :https://open.fe 阅读全文
摘要:
[TOC] 点亮LED灯 硬件连接 找一个LED灯,连接如上图,注意长短引脚,经过这些年的狂轰乱炸,大家对于这个应该不漠视,毕竟Arduino都进教材了。 代码 我们先来看图形化的版本: 是的你没有看错,树莓派点亮 只需要3行代码 。只需要像Python的 编程一样导入需要用到的 类,然后生成一个表 阅读全文
摘要:
50块钱求解决pyqt5加载pdf文档并显示,类似briss软件的效果 阅读全文
摘要:
原因是getOpenFileName的返回值是文件名文件类型的元组,这里直接把元组赋值给了open函数,但是应该是文件名,自己对于代码基础原理不够理解,实际实例代码都有写 我没有仔细观察,花了1个小时解决这个问题 pycharm没有报这个错误,到命令行运行可以很清晰的看到这个错误,pycharm假死 阅读全文
摘要:
原来博客园支持图片上传的,优秀啊,粘贴上传 体验堪比简书啊 阅读全文
摘要:
  阅读全文
摘要:
从Scratch到Python——python turtle 一种比pygame更加简洁的实现 现在很多学校都开设了Scratch课程,学生可以利用Scratch创作丰富的作品,然而Scratch之后的图形化编程语言学习什么内容,是一线老师和Scratch官方共同关注的问题。 转载请注明出处:htt 阅读全文
摘要:
` "之前讲解了从scratch到python,基于python turtle库的实现" ,讲解了用scratch和python turtle绘图的实现,以及让小猫动起来和当角色被单击的例子。 本节课讲继续探索从scratch到python的道路,以猜数游戏为进行讲解。 概述 猜数游戏是一个很经典的 阅读全文
摘要:
从Scratch到Python之角色与造型 继续讲解通过python turtle从积木编程过渡到代码编程的技巧.角色是scratch中很重要的主角,每个角色可以更换不同的造型或者音效,堆叠不同的积木.如果把角色比做人,造型就是人物外观或者动作的变化,比如穿着运动服,打棒球或者走路等不同的造型.接下 阅读全文
摘要:
 我相信,将来Python 阅读全文
摘要:
关于Python语言的介绍安装请参考 "廖雪峰的Python教程" Python是一门解释型语言,虽然不能够像c语言一样编译上传到Arduino——什么你说MicroPython,我们再说Arduino呢——仍然是可以跟Arduino的玩耍的,就像scratch一样。 前言 Python玩转ardu 阅读全文
摘要:
在Scratch中,小猫是可以唱歌的,而且Scratch的声音木块有着丰富的功能,在这方面Python turtle略有欠缺,今天我们就来完善一下. Python声音模块 Python处理声音的模块很多,但是我们要实现的功能并不复杂,所以只需要用到 这个系统自带的模块就好了.我们要的只是实现类似sc 阅读全文
摘要:
大部分人提起儿童编程,就会想到Scratch,然而当儿童升入中学,学习什么语言比较合适呢?我认为,Python是未来的方向,为此我将会把一些经典的Scratch案例用Python重新实现,抛砖引玉,希望能给大家带来一定的启发。我坚信,未来中学的编程教育,Python一定会有自己的一席之地。 作者:少 阅读全文
摘要:
家里路由器不在自己卧室,用树莓派考虑用wifi,之前用Raspberry官方系统,按照教程写的wpa.conf可以连接wifi,后来重新刷ubuntu mate 16.04就不好用了 各种找原因,后来原因找到了,wpa.conf的配置文件中的引号要用双引号的 所以下面这样是不行的 要像下面这样 阅读全文
摘要:
导入必要的第三方库 /usr/lib/python3/dist packages/matplotlib/font_manager.py:273: UserWarning: Matplotlib is building the font cache using fc list. This may ta 阅读全文
摘要:
文件夹 PATH 列表 卷序列号为 00000058 F027:7BEC C:. ├─activeqt │ └─webbrowser │ ├─icons │ └─__pycache__ ├─animation │ ├─animatedtiles │ │ └─images │ ├─appchooser 阅读全文
摘要:
读文件 names Columns这个可以不写,制定索引列是第一列,这样就没有序号 写文件 dataframe 类似于二维列表 充分利用map函数 修改一列的值 筛选列 这种办法可以筛选得到新的df 自动迭代 处理 充分体现了轮子的重要性 如果是一个熟练人员几分钟就搞定了 下面是不是用pandas自 阅读全文
摘要:
读文件 pd.read_csv('path/to/file.txt',header=0,names='ab',index=0) names Columns这个可以不写,制定索引列是第一列,这样就没有序号 写文件 np.tofile("d:/python/np.txt") dataframe 类似于二 阅读全文
摘要:
根据2012年4月5日中国室内装饰协会智能化委员会《智能家居系统产品分类指导手册》的分类依据,智能家居系统产品共分为二十个分类:[5] 控制主机(集中控制器):Smarthome Control Center。 智能照明系统。Intelligent Lighting System(ILS)。 电器控 阅读全文