QLU—寒假第一次训练

2023-10-27 21:59
文章标签 训练 第一次 寒假 qlu

本文主要是介绍QLU—寒假第一次训练,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

A - Classy Numbers(数位dp)

Let's call some positive integer classy if its decimal representation contains no more than 33 non-zero digits. For example, numbers 44, 200000200000, 1020310203 are classy and numbers 42314231, 102306102306, 72774200007277420000 are not.

You are given a segment [L;R][L;R]. Count the number of classy integers xx such that L≤x≤RL≤x≤R.

Each testcase contains several segments, for each of them you are required to solve the problem separately.

Input

The first line contains a single integer TT (1≤T≤1041≤T≤104) — the number of segments in a testcase.

Each of the next TT lines contains two integers LiLi and RiRi (1≤Li≤Ri≤10181≤Li≤Ri≤1018).

Output

Print TT lines — the ii-th line should contain the number of classy integers on a segment [Li;Ri][Li;Ri].

Example

Input

4
1 1000
1024 1024
65536 65536
999999 1000001

Output

1000
1
0
2

算是一个数位dp的模板题吧,如果没看过数位dp可以看下我的博客里的这一篇。

这里要求是找不超过3个非0的数字组成的数,那么state就用来计非0数字的数目。还是看代码里的注释吧

#include<bits/stdc++.h>
#define exp 1e-8
#define mian main
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ll long long
#define pb push_back
#define PI  acos(-1.0)
#define inf 0x3f3f3f3f
#define w(x) while(x--)
#define int_max 2147483647
#define lowbit(x) (x)&(-x)
#define gcd(a,b) __gcd(a,b)
#define pq(x)  priority_queue<x>
#define ull unsigned long long
#define sc(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define pl(a,n) next_permutation(a,a+n)
#define ios ios::sync_with_stdio(false)
#define met(a,x) memset((a),(x),sizeof((a)))
using namespace std;
ll a[20];
ll dp[20][4];  //因为要用到1,2,3,所以二维数组要开到4
ll dfs(int pos,int state,bool limit)//pos代表位数,state记录非0数字的个数,limit数位上界变量
{if(state>3)           //数字个数大于3个,那么返回0return 0;if(pos==0)return 1;if(!limit&&dp[pos][state]!=-1)  //记忆化return dp[pos][state];int up=limit?a[pos]:9;ll ans=0;for(int i=0;i<=up;i++){ans+=dfs(pos-1,state+(i==0?0:1),limit&&i==a[pos]);}if(!limit)dp[pos][state]=ans;return ans;
}
ll solve(ll x)//数位分解
{met(dp,-1);int pos=1;while(x){a[pos++]=x%10;x/=10;}return dfs(pos-1,0,1);
}
int main()
{int t;sc(t);while(t--){met(a,0);ll l,r;scanf("%lld%lld",&l,&r);printf("%lld\n",solve(r)-solve(l-1));}
}

C - Function Height

 

You are given a set of 2n+12n+1 integer points on a Cartesian plane. Points are numbered from 00 to 2n2n inclusive. Let PiPi be the ii-th point. The xx-coordinate of the point PiPi equals ii. The yy-coordinate of the point PiPi equals zero (initially). Thus, initially Pi=(i,0)Pi=(i,0).

The given points are vertices of a plot of a piecewise function. The jj-th piece of the function is the segment PjPj+1PjPj+1.

In one move you can increase the yy-coordinate of any point with odd xx-coordinate (i.e. such points are P1,P3,…,P2n−1P1,P3,…,P2n−1) by 11. Note that the corresponding segments also change.

For example, the following plot shows a function for n=3n=3 (i.e. number of points is 2⋅3+1=72⋅3+1=7) in which we increased the yy-coordinate of the point P1P1 three times and yy-coordinate of the point P5P5 one time:

Let the area of the plot be the area below this plot and above the coordinate axis OX. For example, the area of the plot on the picture above is 4 (the light blue area on the picture above is the area of the plot drawn on it).

Let the height of the plot be the maximum yy-coordinate among all initial points in the plot (i.e. points P0,P1,…,P2nP0,P1,…,P2n). The height of the plot on the picture above is 3.

Your problem is to say which minimum possible height can have the plot consisting of 2n+12n+1 vertices and having an area equal to kk. Note that it is unnecessary to minimize the number of moves.

It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding 10181018.

Input

The first line of the input contains two integers nn and kk (1≤n,k≤10181≤n,k≤1018) — the number of vertices in a plot of a piecewise function and the area we need to obtain.

Output

Print one integer — the minimum possible height of a plot consisting of 2n+12n+1vertices and with an area equals kk. It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding 10181018.

Examples

Input

4 3

Output

1

Input

4 12

Output

3

Input

999999999999999999 999999999999999986

Output

1

Note

One of the possible answers to the first example:

The area of this plot is 3, the height of this plot is 1.

There is only one possible answer to the second example:

The area of this plot is 12, the height of this plot is 3.

这个题大体的题意是给2n+1个点(包括原点),构成三角形,这些三角形的总面积加起来为k,求三角形的顶点平均高度尽可能小的情况下,最大的顶点高度。

因为底是2,所以每个三角形面积即为高

当n>=k时,直接输出1;

如果n<k,则为k/n向上取整

#include<bits/stdc++.h>
#define exp 1e-8
#define mian main
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ll long long
#define pb push_back
#define PI  acos(-1.0)
#define inf 0x3f3f3f3f
#define w(x) while(x--)
#define int_max 2147483647
#define lowbit(x) (x)&(-x)
#define gcd(a,b) __gcd(a,b)
#define pq(x)  priority_queue<x>
#define ull unsigned long long
#define sc(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define pl(a,n) next_permutation(a,a+n)
#define ios ios::sync_with_stdio(false)
#define met(a,x) memset((a),(x),sizeof((a)))
using namespace std;
ll n,k;
int main()
{while(~scanf("%lld%lld",&n,&k)){if(n>=k)printf("1\n");else{if(k%n==0)printf("%lld\n",k/n);else printf("%lld\n",k/n+1);}}
}

D - Diagonal Walking v.2

 

Mikhail walks on a Cartesian plane. He starts at the point (0,0)(0,0), and in one move he can go to any of eight adjacent points. For example, if Mikhail is currently at the point (0,0)(0,0), he can go to any of the following points in one move:

  • (1,0)(1,0);
  • (1,1)(1,1);
  • (0,1)(0,1);
  • (−1,1)(−1,1);
  • (−1,0)(−1,0);
  • (−1,−1)(−1,−1);
  • (0,−1)(0,−1);
  • (1,−1)(1,−1).

If Mikhail goes from the point (x1,y1)(x1,y1) to the point (x2,y2)(x2,y2) in one move, and x1≠x2x1≠x2and y1≠y2y1≠y2, then such a move is called a diagonal move.

Mikhail has qq queries. For the ii-th query Mikhail's target is to go to the point (ni,mi)(ni,mi) from the point (0,0)(0,0) in exactly kiki moves. Among all possible movements he want to choose one with the maximum number of diagonal moves. Your task is to find the maximum number of diagonal moves or find that it is impossible to go from the point (0,0)(0,0) to the point (ni,mi)(ni,mi) in kiki moves.

Note that Mikhail can visit any point any number of times (even the destination point!).

Input

The first line of the input contains one integer qq (1≤q≤1041≤q≤104) — the number of queries.

Then qq lines follow. The ii-th of these qq lines contains three integers nini, mimi and kiki(1≤ni,mi,ki≤10181≤ni,mi,ki≤1018) — xx-coordinate of the destination point of the query, yy-coordinate of the destination point of the query and the number of moves in the query, correspondingly.

Output

Print qq integers. The ii-th integer should be equal to -1 if Mikhail cannot go from the point (0,0)(0,0) to the point (ni,mi)(ni,mi) in exactly kiki moves described above. Otherwise the ii-th integer should be equal to the the maximum number of diagonal moves among all possible movements.

Example

Input

3
2 2 3
4 3 7
10 1 9

Output

1
6
-1

Note

One of the possible answers to the first test case: (0,0)→(1,0)→(1,1)→(2,2)(0,0)→(1,0)→(1,1)→(2,2).

One of the possible answers to the second test case: (0,0)→(0,1)→(1,2)→(0,3)→(1,4)→(2,3)→(3,2)→(4,3)(0,0)→(0,1)→(1,2)→(0,3)→(1,4)→(2,3)→(3,2)→(4,3).

In the third test case Mikhail cannot reach the point (10,1)(10,1) in 9 moves.

题意大体是从(0,0)走到(n,m),最多走k步,可以横着竖着或者斜着走,问可以最多斜着走几步?

这个题算是找规律把,画上几个图就可以了。

当n或m有一个大于k时,就以为这无论如何都走不到目的地,所以直接输出-1.

如果n-m(n为两个数中大的那一个)为奇数,那么就有一步不能走对角线,k要减一,

或者如果走对角线可以直接到终点,k-n(n还是为大的那个)为偶数,k不变(因为除了终点其他点可以多次经过),如果为奇数,就有两步不能走对角线,k-=2;

#include<bits/stdc++.h>
#define exp 1e-8
#define mian main
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ll long long
#define pb push_back
#define PI  acos(-1.0)
#define inf 0x3f3f3f3f
#define w(x) while(x--)
#define int_max 2147483647
#define lowbit(x) (x)&(-x)
#define gcd(a,b) __gcd(a,b)
#define pq(x)  priority_queue<x>
#define ull unsigned long long
#define sc(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define pl(a,n) next_permutation(a,a+n)
#define ios ios::sync_with_stdio(false)
#define met(a,x) memset((a),(x),sizeof((a)))
using namespace std;
ll n,m,k;
int main()
{int t;sc(t);while(t--){scanf("%lld%lld%lld",&n,&m,&k);if(n>k||m>k)printf("-1\n");else {if(n<m)swap(n,m);if((n-m)&1)k--;else if((k-n)&1)k-=2;printf("%lld\n",k);}}
}

还有一个因为没有看群通知所以做了其他的一个题,在这里也写上吧。

GCD Again

Problem Description

Do you have spent some time to think and try to solve those unsolved problem after one ACM contest?
No? Oh, you must do this when you want to become a "Big Cattle".
Now you will find that this problem is so familiar:
The greatest common divisor GCD (a, b) of two positive integers a and b, sometimes written (a, b), is the largest divisor common to a and b. For example, (1, 2) =1, (12, 18) =6. (a, b) can be easily found by the Euclidean algorithm. Now I am considering a little more difficult problem: 
Given an integer N, please count the number of the integers M (0<M<N) which satisfies (N,M)>1.
This is a simple version of problem “GCD” which you have done in a contest recently,so I name this problem “GCD Again”.If you cannot solve it still,please take a good think about your method of study.
Good Luck!

 

Input

Input contains multiple test cases. Each test case contains an integers N (1<N<100000000). A test case containing 0 terminates the input and this test case is not to be processed.

 

Output

For each integers N you should output the number of integers M in one line, and with one line of output for each line in input. 

 

Sample Input

2 4 0

Sample Output

0 1

Author

lcy

题意:给一个N,找小于N里的与N的最大公约数大于1,也就是等价于找出小于N且与N不互质的数的个数,很明显套欧拉函数的模板就好了,ans=N-1-φ(N)。(-1是因为要减去1)。欧拉函数我没写博客,不会的可以百度一下。我当时看的是这一篇

#include<bits/stdc++.h>
#define exp 1e-8
#define mian main
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ll long long
#define pb push_back
#define PI  acos(-1.0)
#define inf 0x3f3f3f3f
#define w(x) while(x--)
#define int_max 2147483647
#define lowbit(x) (x)&(-x)
#define gcd(a,b) __gcd(a,b)
#define pq(x)  priority_queue<x>
#define ull unsigned long long
#define sc(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define pl(a,n) next_permutation(a,a+n)
#define ios ios::sync_with_stdio(false)
#define met(a,x) memset((a),(x),sizeof((a)))
using namespace std;
int n;
int euler(int n)
{int num=n;for(int i=2;i*i<=n;i++){if(n%i==0){num=num/i*(i-1);while(n%i==0)n/=i;}}if(n>1)num=num/n*(n-1);return num;
}
int main()
{while(~sc(n),n!=0){printf("%d\n",n-1-euler(n));}
}

刚刚又补了一个题。。。

E - Vasya and Arrays

 

Vasya has two arrays AA and BB of lengths nn and mm, respectively.

He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the array [1,10,100,1000,10000][1,10,100,1000,10000] Vasya can obtain array [1,1110,10000][1,1110,10000], and from array [1,2,3][1,2,3] Vasya can obtain array [6][6].

Two arrays AA and BB are considered equal if and only if they have the same length and for each valid ii Ai=BiAi=Bi.

Vasya wants to perform some of these operations on array AA, some on array BB, in such a way that arrays AA and BB become equal. Moreover, the lengths of the resulting arrays should be maximal possible.

Help Vasya to determine the maximum length of the arrays that he can achieve or output that it is impossible to make arrays AA and BB equal.

Input

The first line contains a single integer n (1≤n≤3⋅105)n (1≤n≤3⋅105) — the length of the first array.

The second line contains nn integers a1,a2,⋯,an (1≤ai≤109)a1,a2,⋯,an (1≤ai≤109) — elements of the array AA.

The third line contains a single integer m (1≤m≤3⋅105)m (1≤m≤3⋅105) — the length of the second array.

The fourth line contains mm integers b1,b2,⋯,bm (1≤bi≤109)b1,b2,⋯,bm (1≤bi≤109) - elements of the array BB.

Output

Print a single integer — the maximum length of the resulting arrays after some operations were performed on arrays AA and BB in such a way that they became equal.

If there is no way to make array equal, print "-1".

Examples

Input

5
11 2 3 5 7
4
11 7 3 7

Output

3

Input

2
1 2
1
100

Output

-1

Input

3
1 2 3
3
1 2 3

Output

3

题意:给两个数组,这两个数组中相邻的数可以相加,问如果可以让两个数组一模一样,问数组中最多可以有多少个数,一模一样就是说想最后这个例子,两个数组都是1,2,3,数一样,顺序也一样。

首先判断这两个数组的和相不相等,如果不相等直接输出-1,如果相等继续判断,直接模拟就好了,从第一个数组的第一个数判断如果不相等,看看哪个数大,小的那个就往后加,直到相等为止。具体看代码吧。

还要注意如果是int会爆掉,要用long long

#include<bits/stdc++.h>
#define exp 1e-8
#define mian main
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ll long long
#define pb push_back
#define PI  acos(-1.0)
#define inf 0x3f3f3f3f
#define w(x) while(x--)
#define int_max 2147483647
#define lowbit(x) (x)&(-x)
#define gcd(a,b) __gcd(a,b)
#define pq(x)  priority_queue<x>
#define ull unsigned long long
#define sc(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define pl(a,n) next_permutation(a,a+n)
#define ios ios::sync_with_stdio(false)
#define met(a,x) memset((a),(x),sizeof((a)))
using namespace std;
const int N=3e5+10;
int  n1,n2;
ll a[N],b[N];
int main()
{while(~scanf("%d",&n1)){met(a,0);met(b,0);for(int i=1;i<=n1;i++){scanf("%lld",&a[i]);a[0]+=a[i];}sc(n2);for(int i=1;i<=n2;i++){scanf("%lld",&b[i]);b[0]+=b[i];}if(a[0]!=b[0])printf("-1\n");else {int ans=0;int k=1;for(int i=1;i<=n1;i++,k++){bool flag=true;while(a[i]!=b[k]){        //两个数是否相等if(a[i]>b[k])b[++k]+=b[k-1];elsea[++i]+=a[i-1];if(i>n1||k>n2){  //超出范围就退出flag=false;break;}}if(flag==true)ans++;}if(ans==0)printf("-1\n");elseprintf("%d\n",ans);}}
}

 

这篇关于QLU—寒假第一次训练的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/288684

相关文章

MiniGPT-3D, 首个高效的3D点云大语言模型,仅需一张RTX3090显卡,训练一天时间,已开源

项目主页:https://tangyuan96.github.io/minigpt_3d_project_page/ 代码:https://github.com/TangYuan96/MiniGPT-3D 论文:https://arxiv.org/pdf/2405.01413 MiniGPT-3D在多个任务上取得了SoTA,被ACM MM2024接收,只拥有47.8M的可训练参数,在一张RTX

Spark MLlib模型训练—聚类算法 PIC(Power Iteration Clustering)

Spark MLlib模型训练—聚类算法 PIC(Power Iteration Clustering) Power Iteration Clustering (PIC) 是一种基于图的聚类算法,用于在大规模数据集上进行高效的社区检测。PIC 算法的核心思想是通过迭代图的幂运算来发现数据中的潜在簇。该算法适用于处理大规模图数据,特别是在社交网络分析、推荐系统和生物信息学等领域具有广泛应用。Spa

SigLIP——采用sigmoid损失的图文预训练方式

SigLIP——采用sigmoid损失的图文预训练方式 FesianXu 20240825 at Wechat Search Team 前言 CLIP中的infoNCE损失是一种对比性损失,在SigLIP这个工作中,作者提出采用非对比性的sigmoid损失,能够更高效地进行图文预训练,本文进行介绍。如有谬误请见谅并联系指出,本文遵守CC 4.0 BY-SA版权协议,转载请联系作者并注

Detectorn2预训练模型复现:数据准备、训练命令、日志分析与输出目录

Detectorn2预训练模型复现:数据准备、训练命令、日志分析与输出目录 在深度学习项目中,目标检测是一项重要的任务。本文将详细介绍如何使用Detectron2进行目标检测模型的复现训练,涵盖训练数据准备、训练命令、训练日志分析、训练指标以及训练输出目录的各个文件及其作用。特别地,我们将演示在训练过程中出现中断后,如何使用 resume 功能继续训练,并将我们复现的模型与Model Zoo中的

C++中第一次听到构造函数

在C++中第一次听到构造函数这个名词,在C#中又遇到了。   在创建某个类时,由于对该对象的状态(数据)不是很明确,因此需要对其进行初始化。比如说我们要在长方形这个类中创建一个对象,或者说新建一个长方形,那么我们首先要确定他的长和宽,假如我们无法确定它的长和宽,那么我们是无法造出一个长方形来的。所以就要使用这个长方形类中一个用来构造该类所有对象的函数--构造函数。由于该函数要在创建一个新对象

多云架构下大模型训练的存储稳定性探索

一、多云架构与大模型训练的融合 (一)多云架构的优势与挑战 多云架构为大模型训练带来了诸多优势。首先,资源灵活性显著提高,不同的云平台可以提供不同类型的计算资源和存储服务,满足大模型训练在不同阶段的需求。例如,某些云平台可能在 GPU 计算资源上具有优势,而另一些则在存储成本或性能上表现出色,企业可以根据实际情况进行选择和组合。其次,扩展性得以增强,当大模型的规模不断扩大时,单一云平

神经网络训练不起来怎么办(零)| General Guidance

摘要:模型性能不理想时,如何判断 Model Bias, Optimization, Overfitting 等问题,并以此着手优化模型。在这个分析过程中,我们可以对Function Set,模型弹性有直观的理解。关键词:模型性能,Model Bias, Optimization, Overfitting。 零,领域背景 如果我们的模型表现较差,那么我们往往需要根据 Training l

如何创建训练数据集

在 HuggingFace 上创建数据集非常方便,创建完成之后,通过 API 可以方便的下载并使用数据集,在 Google Colab 上进行模型调优,下载数据集速度非常快,本文通过 Dataset 库创建一个简单的训练数据集。 首先安装数据集依赖 HuggingFace datasetshuggingface_hub 创建数据集 替换为自己的 HuggingFace API key

【YOLO 系列】基于YOLOV8的智能花卉分类检测系统【python源码+Pyqt5界面+数据集+训练代码】

前言: 花朵作为自然界中的重要组成部分,不仅在生态学上具有重要意义,也在园艺、农业以及艺术领域中占有一席之地。随着图像识别技术的发展,自动化的花朵分类对于植物研究、生物多样性保护以及园艺爱好者来说变得越发重要。为了提高花朵分类的效率和准确性,我们启动了基于YOLO V8的花朵分类智能识别系统项目。该项目利用深度学习技术,通过分析花朵图像,自动识别并分类不同种类的花朵,为用户提供一个高效的花朵识别

深度学习与大模型第3课:线性回归模型的构建与训练

文章目录 使用Python实现线性回归:从基础到scikit-learn1. 环境准备2. 数据准备和可视化3. 使用numpy实现线性回归4. 使用模型进行预测5. 可视化预测结果6. 使用scikit-learn实现线性回归7. 梯度下降法8. 随机梯度下降和小批量梯度下降9. 比较不同的梯度下降方法总结 使用Python实现线性回归:从基础到scikit-learn 线性