/** 斐波那契思路(黄金比例):* 首先斐波那契为 1 1 2 3 5 8 13 21 34 55.。。 第个数开始,等于前面2个数的和。而且n/n+1无限接近与0.618* f[i] = f[i-1] + f[i-2]* */import java.util.Arrays;public clas ...
分类:
编程语言 时间:
2020-10-09 20:41:20
阅读次数:
21
题目: 设计一个平均时间为O(n)的算法,在n(1<=n<=1000)个无序的整数中找出第k小的数。 提示:函数int partition(int a[],int left,int right)的功能是根据a[left]~a[right]中的某个元素x(如a[left])对a[left]~a[rig ...
分类:
编程语言 时间:
2020-10-09 20:22:27
阅读次数:
38
import turtle n = eval(input("请输入五角星的长度")) turtle.begin_fill() #开始填充颜色 i = 0 while i < 5: turtle.forward(n) turtle.right(180-36) i += 1 turtle.color(" ...
分类:
其他好文 时间:
2020-10-09 20:20:03
阅读次数:
33
实验方法 //输出运行时间 #include <bits/stdc++.h> using namespace std; const int MODE = 10000; int main(){ freopen("a1.txt", "w", stdout); int k = 100; while(k-- ...
分类:
其他好文 时间:
2020-10-09 20:18:04
阅读次数:
24
LeetCode 75 颜色分类 问题描述: 给定一个包含红色、白色和蓝色,一共 n 个元素的数组,原地对它们进行排序,使得相同颜色的元素相邻,并按照红色、白色、蓝色顺序排列。 此题中,我们使用整数 0、 1 和 2 分别表示红色、白色和蓝色。 注意: 不能使用代码库中的排序函数来解决这道题。 三指 ...
分类:
其他好文 时间:
2020-10-07 21:06:11
阅读次数:
23
题目: 给定一个整数i,求出另一个整数j,使i和j在用8位二进制表示时互为逆序。 实验代码: while(1): n=int(input('请输入一个数:')) s='' for j in range(8): s+=str(n%2) n//=2 s=str(s) sum=0 j=len(s)-1 f ...
分类:
编程语言 时间:
2020-10-07 20:38:28
阅读次数:
27
题目: 将两个升序链表合并为一个新的 升序 链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *nex ...
分类:
其他好文 时间:
2020-10-07 20:36:35
阅读次数:
21
题意 统计树中的每一层有多少叶子结点,要求逐层输出 思路 逐层输出,刚好层序遍历是逐层扩展,所以我就直接用BFS了 代码 #include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <v ...
分类:
其他好文 时间:
2020-10-06 20:54:35
阅读次数:
26
9.26 H.HDU 6562 线段树操作特点:1.能统计出一个操作对一个区间整体的影响;2.能通过标记表示出该操作对左右子区间的影响;3.标记的含义为子区间应当进行的操作,标记应当能够合并(具有先后顺序)。此题中我们维护区间\(10^{a}\) 的和,则区间的值的增加量为 \(d * 10^{a} ...
分类:
其他好文 时间:
2020-10-06 20:45:51
阅读次数:
25
class Solution { public ListNode addTwoNumbers(ListNode l1, ListNode l2) { if(l1==null){ return l2; } if(l2==null){ return l1; } int t=0; ListNode res ...
分类:
其他好文 时间:
2020-10-06 20:10:27
阅读次数:
24