340

3个月前
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

const int N = 100002;

int L[N];

int check(double tar,int n){
int s = 0;
for(int i = 0; i < n; i++){
s += (int)(L[i]/tar);
}
return s;
}

int main(){
int n,m;
cin>>n>>m;
int maxL = 0;
for (int i = 0; i < n; i ++ ){
cin>>L[i];
maxL = max(maxL, L[i]);
}
double le = 0;
double ri = 1e9;
while(ri-le > 1e-3){
double mid = le + (ri-le)/2;
if(check(mid,n) >= m) le = mid;
else
ri = mid;
}
printf("%.2f",le);

}


3个月前
class Solution {
public:
int dp[102] = {0};
int numDecodings(string s) {
const int n = s.size();
if(s[0] != '0') {
dp[1] = 1;
dp[0] = 1;
}
for(int i = 2; i <= n; i++){
if((s[i-2] != '2' && s[i-2] - '0'  != 1) && s[i-1] == '0'){
break;
}
if(s[i-1] == '0')
dp[i] = dp[i-2];
else if(s[i-2] == '0' || s[i-2] - '0' > 2 ||
(s[i-2] - '0' == 2 && s[i-1] - '0' > 6))
dp[i] = dp[i-1];
else
dp[i] = dp[i-1] +dp[i-2];
}
return dp[n];
}
};


3个月前
class Solution {
public:
int dp[102] = {0};
int numDecodings(string s) {
const int n = s.size();
if(s[0] != '0') {
dp[1] = 1;
dp[0] = 1;
}
for(int i = 2; i <= n; i++){
if((s[i-2] != '2' && s[i-2] - '0'  != 1) && s[i-1] == '0'){
break;
}
if(s[i-1] == '0')
dp[i] = dp[i-2];
else if(s[i-2] == '0' || s[i-2] - '0' > 2 ||
(s[i-2] - '0' == 2 && s[i-1] - '0' > 6))
dp[i] = dp[i-1];
else
dp[i] = dp[i-1] +dp[i-2];
}
return dp[n];
}
};


3个月前
#include<iostream>
using namespace std;
const int N = 17;
int dp[N];
int main(){
int n;
cin>>n;
dp[1] = 1;
dp[2] = 2;
for (int i = 3; i <= n; i ++ ){
dp[i] = dp[i-1] + dp[i-2];
}
cout<<dp[n];
}


3个月前

Java 自定义类数组，和比较器；

Comparator 实现

import java.util.*;
public class Main{
static class Node{
int v;
Node(){
this.v = 0;
}
Node(int v){
this.v = v;
}
}
public static void main(String[] args){

Node[] ddd = new Node[3];
Arrays.fill(ddd,new Node());
ddd[0] = new Node(1);
ddd[1] = new Node(2);
ddd[2] = new Node(3);
Arrays.sort(ddd, 0,3,new Comparator<Node>(){
public int compare(Node a, Node b){
return b.v - a.v;}
});//自定义比较器，return 大于零这表示要交换；
System.out.println(ddd[2].v);

}
}



Comparable实现

import java.util.*;
public class Main{
static class Node implements Comparable<Node>{
int v;
Node(){
this.v = 0;
}
Node(int v){
this.v = v;
}
public int compareTo(Node node){
return node.v - v;
}
}
static int[] prior = new int[100002];
public static void main(String[] args){

Node[] ddd = new Node[3];
Arrays.fill(ddd,new Node());
ddd[0] = new Node(1);
ddd[1] = new Node(2);
ddd[2] = new Node(3);
Arrays.sort(ddd, 0,3/*,new Comparator<Node>(){
public int compare(Node a, Node b){
return b.v - a.v;}
}*/);
System.out.println(ddd[2].v);

}
}



3个月前

eg: 1 2 3

a 选与不选
1 2 3
1 2
1 3
1
2 3
2
3
92

b 全排列有顺序
1 2 3
1 3 2
2 1 3
2 3 1
.....
823

c 组合
1 2
1 3
2 3
.....
93