新生43
HEX
HEX:
In programming, hexadecimal notation is often used.
In hexadecimal notation, besides the ten digits 0,1,…,9, the six letters A, B, C, D, E and F are used to represent the values 10,11,12,13,14 and 15, respectively.
In this problem, you are given two letters X and Y. Each X and Y is A, B, C, D, E or F.
When X and Y are seen as hexadecimal numbers, which is larger?
Constraints
Each X and Y is A, B, C, D, E or F.
In hexadecimal notation, besides the ten digits 0,1,…,9, the six letters A, B, C, D, E and F are used to represent the values 10,11,12,13,14 and 15, respectively.
In this problem, you are given two letters X and Y. Each X and Y is A, B, C, D, E or F.
When X and Y are seen as hexadecimal numbers, which is larger?
Constraints
Each X and Y is A, B, C, D, E or F.
输入
Input is given from Standard Input in the following format:
X Y
X Y
输出
If X is smaller, print <; if Y is smaller, print >; if they are equal, print =.
样例输入 Copy
A B
样例输出 Copy
<
提示
10<11
#include<iostream> #include<cmath> #include<map> using namespace std; int main(){ char ch[10]={'A','B','C','D','E','F'}; char a,b; cin>>a>>b; int x,y; for(int i=0;i<6;i++) { if(a==ch[i]) x=i; if(b==ch[i]) y=i; } if(x>y) cout<<">"<<endl; else if(x<y) cout<<"<"<<endl; else if(x==y) cout<<"="<<endl; return 0; }
#include<iostream> #include<cmath> #include<map> using namespace std; map<char,int> mp; int main(){ int x,y; char a,b,A,B,C,D,E,F; mp['A']=10; mp['B']=11; mp['C']=12; mp['D']=13; mp['E']=14; mp['F']=15; cin>>a>>b; x=mp[a]; y=mp[b]; if(x>y) cout<<">"<<endl; else if(x<y) cout<<"<"<<endl; else if(x==y) cout<<"="<<endl; return 0; }
map也可以,一一对应的关系
Two Switches
题目描述
Alice and Bob are controlling a robot. They each have one switch that controls the robot.
Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up.
Bob started holding down his button C second after the start-up, and released his button D second after the start-up.
For how many seconds both Alice and Bob were holding down their buttons?
Constraints
0≤A<B≤100
0≤C<D≤100
All input values are integers.
Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up.
Bob started holding down his button C second after the start-up, and released his button D second after the start-up.
For how many seconds both Alice and Bob were holding down their buttons?
Constraints
0≤A<B≤100
0≤C<D≤100
All input values are integers.
输入
Input is given from Standard Input in the following format:
A B C D
A B C D
输出
Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons.
样例输入 Copy
0 75 25 100
样例输出 Copy
50
提示
Alice started holding down her button 0 second after the start-up of the robot, and released her button 75 second after the start-up.
Bob started holding down his button 25 second after the start-up, and released his button 100 second after the start-up.
Therefore, the time when both of them were holding down their buttons, is the 50 seconds from 25 seconds after the start-up to 75 seconds after the start-up.
Bob started holding down his button 25 second after the start-up, and released his button 100 second after the start-up.
Therefore, the time when both of them were holding down their buttons, is the 50 seconds from 25 seconds after the start-up to 75 seconds after the start-up.
这题nm纯纯一个大无语,玩nm文字游戏呢啊,sb题
读题都比写题时间长
可能我理解不太好,大佬勿喷
Multiple Clocks
题目描述
We have N clocks. The hand of the i-th clock (1≤i≤N) rotates through 360° in exactly Ti seconds.
Initially, the hand of every clock stands still, pointing directly upward.
Now, Dolphin starts all the clocks simultaneously.
In how many seconds will the hand of every clock point directly upward again?
Constraints
1≤N≤100
1≤Ti≤1018
All input values are integers.
The correct answer is at most 1018 seconds.
Initially, the hand of every clock stands still, pointing directly upward.
Now, Dolphin starts all the clocks simultaneously.
In how many seconds will the hand of every clock point directly upward again?
Constraints
1≤N≤100
1≤Ti≤1018
All input values are integers.
The correct answer is at most 1018 seconds.
输入
Input is given from Standard Input in the following format:
N
T1
:
TN
N
T1
:
TN
输出
Print the number of seconds after which the hand of every clock point directly upward again.
样例输入 Copy
2
2
3
样例输出 Copy
6
提示
We have two clocks. The time when the hand of each clock points upward is as follows:
·Clock 1: 2, 4, 6, … seconds after the beginning
·Clock 2: 3, 6, 9, … seconds after the beginning
Therefore, it takes 6 seconds until the hands of both clocks point directly upward.
·Clock 1: 2, 4, 6, … seconds after the beginning
·Clock 2: 3, 6, 9, … seconds after the beginning
Therefore, it takes 6 seconds until the hands of both clocks point directly upward.
这题思路很简单,挨个求最小公倍数,其中最小公倍数的求法是m*n/gcd(m,n)
这个题的数据范围很大
我再加上一组数据
5 2 5 10 1000000000000000000 1000000000000000000
输出答案就知道了,所以要先除再乘
#include<iostream> #include<cmath> typedef long long int ll; using namespace std; ll gcd(ll n,ll m) { if(n%m==0) return m; else return gcd(m,n%m); } ll gsy(ll n,ll m) { return n/gcd(n,m)*m; } int main(){ ll n,t,t1; cin>>n; cin>>t; for(int i=2;i<=n;i++) { cin>>t1; t=gsy(t1,t); } cout<<t<<endl; return 0; }
真奇怪,读题的时候明明注意到了,后来分心看其他题目了,这个点就没注意到...
摆花:
题目描述
小明的花店新开张,为了吸引顾客,他想在花店的门口摆上一排花,共m盆。通过调查顾客的喜好,小明列出了顾客最喜欢的n种花,从1到n标号。为了在门口展出更多种花,规定第i种花不能超过ai盆,摆花时同一种花放在一起,且不同种类的花需按标号的从小到大的顺序依次摆列。
试编程计算,一共有多少种不同的摆花方案。
试编程计算,一共有多少种不同的摆花方案。
输入
第一行包含两个正整数n和m,中间用一个空格隔开。
第二行有n个整数,每两个整数之间用一个空格隔开,依次表示a1、a2、……an。
0<n≤100,0<m≤100,0≤ ai≤100
输出
输出只有一行,一个整数,表示有多少种方案。注意:因为方案数可能很多,请输出方案数对1000007取模的结果。
样例输入 Copy
2 4
3 2
样例输出 Copy
2
递推+多重背包?
#include<iostream> using namespace std; const int N=110; const int mod=1000007; int s[N],f[N][N]; int main(){ int n,m,t; cin>>n>>m; for(int i=1;i<=n;i++) { cin>>t; s[i]=t; } f[0][0]=1; for(int i=1;i<=n;i++) { for(int j=0;j<=m;j++) { for(int k=0;k<=s[i]&&k<=j;k++) { f[i][j]=(f[i][j]+f[i-1][j-k])%mod; } } } cout<<f[n][m]<<endl; return 0; } /*令f[i][j]是第i种放j盆花的方案数 3 2 3 1 1 2 2 1 1+1=2 现在加上前者的状态 */
一维优化:
#include<iostream> using namespace std; const int N=110; const int mod=1000007; int s[N],f[N]; int main(){ int n,m,t; cin>>n>>m; for(int i=1;i<=n;i++) { cin>>t; s[i]=t; } f[0]=1; for(int i=1;i<=n;i++) { for(int j=m;j>=0;j--) { for(int k=1;k<=s[i];k++) { if(j>=k) f[j]=(f[j]+f[j-k])%mod; } } } cout<<f[m]<<endl; return 0; }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具