Atcoder 092
A - Traveling Budget
Time limit : 2sec / Memory limit : 256MB
Score : 100 points
Problem Statement
You planned a trip using trains and buses. The train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket. Similarly, the bus fare will be C yen if you buy ordinary tickets along the way, and Dyen if you buy an unlimited ticket.
Find the minimum total fare when the optimal choices are made for trains and buses.
Constraints
- 1≤A≤1 000
- 1≤B≤1 000
- 1≤C≤1 000
- 1≤D≤1 000
- All input values are integers.
Input
Input is given from Standard Input in the following format:
A B C D
Output
Print the minimum total fare.
Sample Input 1
600 300 220 420
Sample Output 1
520
The train fare will be 600 yen if you buy ordinary tickets, and 300 yen if you buy an unlimited ticket. Thus, the optimal choice for trains is to buy an unlimited ticket for 300 yen. On the other hand, the optimal choice for buses is to buy ordinary tickets for 220 yen.
Therefore, the minimum total fare is 300+220=520 yen.
Sample Input 2
555 555 400 200
Sample Output 2
755
Sample Input 3
549 817 715 603
Sample Output 3
1152
1 #include <iostream> 2 #include <vector> 3 #include <algorithm> 4 #include <string> 5 #include <string.h> 6 #include <cstring> 7 #include <stdio.h> 8 #define lowbit(x) x&(-x) 9 10 using namespace std; 11 const int maxn=105; 12 typedef long long ll; 13 14 15 int main(){ 16 ios::sync_with_stdio(0); 17 ll a,b,c,d; 18 cin>>a>>b>>c>>d; 19 ll minn=min(a,b); 20 ll minn2=min(c,d); 21 cout<<minn+minn2<<endl; 22 return 0; 23 }
B - Chocolate
Time limit : 2sec / Memory limit : 256MB
Score : 200 points
Problem Statement
Some number of chocolate pieces were prepared for a training camp. The camp had N participants and lasted for D days. The i-th participant (1≤i≤N) ate one chocolate piece on each of the following days in the camp: the 1-st day, the (Ai+1)-th day, the (2Ai+1)-th day, and so on. As a result, there were X chocolate pieces remaining at the end of the camp. During the camp, nobody except the participants ate chocolate pieces.
Find the number of chocolate pieces prepared at the beginning of the camp.
Constraints
- 1≤N≤100
- 1≤D≤100
- 1≤X≤100
- 1≤Ai≤100 (1≤i≤N)
- All input values are integers.
Input
Input is given from Standard Input in the following format:
N D X A1 A2 : AN
Output
Find the number of chocolate pieces prepared at the beginning of the camp.
Sample Input 1
3 7 1 2 5 10
Sample Output 1
8
The camp has 3 participants and lasts for 7 days. Each participant eats chocolate pieces as follows:
- The first participant eats one chocolate piece on Day 1, 3, 5 and 7, for a total of four.
- The second participant eats one chocolate piece on Day 1 and 6, for a total of two.
- The third participant eats one chocolate piece only on Day 1, for a total of one.
Since the number of pieces remaining at the end of the camp is one, the number of pieces prepared at the beginning of the camp is 1+4+2+1=8.
Sample Input 2
2 8 20 1 10
Sample Output 2
29
Sample Input 3
5 30 44 26 18 81 18 6
Sample Output 3
56
1 #include <iostream> 2 #include <vector> 3 #include <algorithm> 4 #include <string> 5 #include <string.h> 6 #include <cstring> 7 #include <stdio.h> 8 #define lowbit(x) x&(-x) 9 10 using namespace std; 11 const int maxn=110; 12 typedef long long ll; 13 int a[maxn]; 14 15 int main(){ 16 ios::sync_with_stdio(0); 17 int n,d,x; 18 cin>>n>>d>>x; 19 ll m=0; 20 memset(a,0,sizeof(a)); 21 for(int i=0;i<n;i++){ 22 cin>>a[i]; 23 } 24 int tmp=0; 25 for(int i=0;i<n;i++){ 26 tmp=a[i]; 27 if(tmp<d) { 28 tmp+=1; 29 m+=2; 30 } 31 else { 32 ++m; 33 continue; 34 } 35 while(tmp<d){ 36 tmp+=a[i]; 37 if(tmp<=d) 38 ++m; 39 else break; 40 } 41 } 42 cout<<m+x<<endl; 43 return 0; 44 }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· C++代码改造为UTF-8编码问题的总结
· DeepSeek 解答了困扰我五年的技术问题
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 用 C# 插值字符串处理器写一个 sscanf
· DeepSeek智能编程
· 精选4款基于.NET开源、功能强大的通讯调试工具
· [翻译] 为什么 Tracebit 用 C# 开发
· 腾讯ima接入deepseek-r1,借用别人脑子用用成真了~
· DeepSeek崛起:程序员“饭碗”被抢,还是职业进化新起点?