实验方法 //输出运行时间 #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
#include <bits/stdc++.h> using namespace std; stack<char> stack_op; stack<int> stack_num; char str[10000]; string change; int pow(int x, int y) { int ...
分类:
其他好文 时间:
2020-10-06 20:08:42
阅读次数:
25
题意简述 题目链接 给定一n个点、m条边的森林,q次操作,操作分两种:1.给定一个点x,要求x所在的树的直径;2.给定两个点x,y,选取x所在树中的一个点u,y所在树中的一个点v,新增一条边(u,v),合并两棵树,使得合并后的新树的直径最小。 算法概述 对于初始的森林,显然可以dp一遍求出所有树的原 ...
分类:
其他好文 时间:
2020-10-05 21:55:02
阅读次数:
30
#include<bits/stdc++.h> using namespace std; const int N = 300010; vector<int>p[N]; int ans[N]; int main() { int t; scanf("%d",&t); while(t --) { int ...
分类:
其他好文 时间:
2020-10-05 21:46:03
阅读次数:
23