PAT 1011 World Cup Betting
题目
题解没有难度,会用 api 就好了。
PAT 1010 Radix
题目
思路
将两个进行比较多数都转变成10进制
long long itoa(string n , long long radix)
这边都是需要 long long 类型多, 因为 radix 和 进制转化都会溢出
另一种容易理解的实现
假设 此时 tag =1 ,那么需要比较的就是N2, 要从 radix[left, right] 中一个个 遍历, 是的 N2转化的 radix 进制的结果 和 N1 转化成 radix2 (参数给的 radix)进制一样;
1. 确定 left , 最小值 一定是 给定 N2 中的 最大的 digit + 1。
1. 确定 right ,我们不知道 ,但一定 比 N1 进制转化后的小,设为 itoa(N2, radix) ,但有可能 left 比 itoa(N2, radix) 大 , 所以 right = max(left , itoa(N2, radix);
二分查找
我们要注意 ,当 发生进制转化的时候, 很有肯能发生溢出, 毕竟10位数的运算真的很 ...
设计模式-静态代理
静态代理:
UserService
UserClinet 需要被代理的对象
Porxy 代理类
测试Demo
运行结果:
缺点总结:
当需要代理 多个类时,由于代理对象要实现与代理对象一致的接口,有两种方式:
只为维护一个代理类,但是代理类要实现多个接口,这样就导致代理类过于庞大
新建多个代理类,每个代理对象 对应 一个代理类,这样就会产生过多的代理类
当接口需要增加,删除,修改方法的时候,代理对象和代理类都要同时修改,不易维护
动态代理JDK动态代理
创建自定义的Handler,需要实现 InvocationHandler 这个接口
测试, 调用 java.lang.reflect中的 Proxy 中的 newProxyInstance 方法,需要代理类的 ClassLoader ,父类的所有 Interface ,和自己定义的 Handler。
运行结果
CGLIB动态代理
创建目标类 TargetClass
实现自定义的 Handler (Intercepter)
使用 Enhancer ,传递目标对象,设置Handler ,用Enhancer创 ...
PAT-1009 Product of Polynomials
题目描述1009 Product of Polynomials (25 分)
This time, you are supposed to find A×B where A and B are two polynomials.
Input Specification:Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial:
K N1 a**N1 N2 a**N2 … N**K aNK
where K is the number of nonzero terms in the polynomial, N**i and aNi (i=1,2,⋯,K) are the exponents and coefficients, respectively. It is given that 1≤K≤10, 0≤N**K<⋯<N2<N1≤1000.
Output Specification:Fo ...
PAT-1007 Maximum Subsequence Sum
题目描述1007 Maximum Subsequence Sum (25 分)
Given a sequence of K integers { N1, N2, …, N**K }. A continuous subsequence is defined to be { N**i, N**i+1, …, N**j } where 1≤i≤j≤K. The Maximum Subsequence is the continuous subsequence which has the largest sum of its elements. For example, given sequence { -2, 11, -4, 13, -5, -2 }, its maximum subsequence is { 11, -4, 13 } with the largest sum being 20.
Now you are supposed to find the largest sum, together with the first and the last numbers of the m ...
PAT-1006 Sign In and Sign Out
题目描述1006 Sign In and Sign Out (25 分)
At the beginning of every day, the first person who signs in the computer room will unlock the door, and the last one who signs out will lock the door. Given the records of signing in’s and out’s, you are supposed to find the ones who have unlocked and locked the door on that day.
Input Specification:Each input file contains one test case. Each case contains the records for one day. The case starts with a positive integer M, which is the total number of recor ...
无题
自己的题解123456789101112131415161718192021222324252627282930313233343536//// Created by 张旭辉 on 2021/8/12.//#include<iostream>#include<cstring>using namespace std;int main(){ string s ; cin>>s; string enums[10]={ "zero", "one", "two", "three", "four", "five", "six", "seven", "eight&q ...
PAT-1004 Counting Leaves
题目描述1004 Counting Leaves (30 分)
A family hierarchy is usually presented by a pedigree tree. Your job is to count those family members who have no child.
Input Specification:Each input file contains one test case. Each case starts with a line containing 0<N<100, the number of nodes in a tree, and M (<N), the number of non-leaf nodes. Then M lines follow, each in the format:
1ID K ID[1] ID[2] ... ID[K]
where ID is a two-digit number representing a given non-leaf node, K is the number of i ...
PAT-1003 Emergency
题目描述1003 Emergency (25 分)
As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams in each city and the length of each road between any pair of cities are marked on the map. When there is an emergency call to you from some other city, your job is to lead your men to the place as quickly as possible, and at the mean time, call up as many hands on the way as possible.
Input Spe ...
图论 c++
Step1:Basic Theoretical Knowledge有向图无向图连通图完全图连通分量
Step2:Demos Of PracticeC++ 稀疏图(临接表实现)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114//// Created by 张旭辉 on 2021/7/27.//#ifndef TESTDEMO_SPARSEGRAPH_H#define TESTDEMO_SPARSEGRAPH_H#include <vector>using namespace std;class SparseGraph {private: int n ...