当前位置:网站首页>Reflection summary of Haut OJ freshmen on Wednesday
Reflection summary of Haut OJ freshmen on Wednesday
2022-07-05 05:20:00 【hunziHang】
problem A: The battle of the king
Problem description :
As a new boss ,H Classmates and T The two students began to compete for the title of champion .
H Classmate said : I smoke every week a/b Time for study , I'm the king of volumes !
T Classmate said : I'm... Every week x/y I spend all my time studying , More than you , I'm the king !
H Students are not convinced , Retort : Obviously I have more study time than you , I am !
Now? , The two of them want to know , Who has more study time .
Input
Four nonnegative integers in a row ,a,b,x,y
(a<=b,x<=y ,< a,b,x,y <= 100 000 000, b , y It's not equal to 0)
Output
If small H More study time , Output "H is juanwang!" ;
If small T More study time , Output "T is juanwang!" ;
If two people study for the same amount of time , Output "We are juanwang!" ;
( Output without quotes )
The sample input
1 2 3 4
Sample output
T is juanwang!
Cause analysis :
1. The accuracy of the first drive is too high (1e-6), You should drive it as big as possible 1e-20;
2. double You can't judge the equal sign directly .( Because the precision of floating-point type is limited , After operation, there may be rounding error )
3. You can also use General points directly compare molecular sizes , The above problems are avoided .( More accurate )
Solution :
1. Accuracy determines a range
#include <iostream>
#include <algorithm>
#include <cmath>
#define double long double
const double eps = 1e-20 ;
int dcmp(double x,double y){
if(fabs(x - y ) < eps) return 0 ;
if(x < y) return -1;
return 1 ;
}
int main()
{
double a, b , x , y ;
scanf("%d%d%d%d" ,&a ,&b ,&x ,&y) ;
double s = a/b ;
double u = x/y ;
if(dcmp(s,u) > 0)
printf("H is juanwang!\n") ;
else if(dcmp(s,u) < 0)
printf("T is juanwang!\n") ;
else
printf("We are juanwang!\n") ;
return 0 ;
}
2. General points
#include <iostream>
int main()
{
long long a , b , x , y ;
scanf("%d%d%d%d",&a,&b,&x,&y) ;
a*= y ;
x*= b ;
if(a > x)
printf("H is juanwang!\n") ;
else if(a < x)
printf("T is juanwang!\n") ;
else
printf("We are juanwang!\n") ;
return 0;
}
problem B: The card game ( To be updated )
Problem description :
as everyone knows ,acmer We play cards , If you lose, you have to write a solution .
S The senior lost a lot of questions because of playing cards , Now? S Seniors want to play a card game to challenge freshmen .
The rules of the game are like this :
A deck of cards has 54 Zhang , We don't want big and small kings in this game for the time being , Then we have 52 Cards can be used , There are four colors , Each decor 13 Cards .
At the beginning of the game, two people take turns to take away the cards , It is stipulated that each person can take any suit of cards each time most n Zhang , And every time I take these cards It can only be the same design and color ,( You don't have to be the same as the other party's suit ), You can't leave it alone ;
Last The party who has no cards to take is the loser .
S Seniors want freshmen , So let the other party take it first .
because S Seniors are extremely smart , In order to win him , What must be adopted is the optimal strategy .
Input :
An integer n(1<= n <=13), Represents the maximum number of cards that can be taken each time .
Output :
If freshmen can win s School leader , Output “%%%” ;
If the freshman loses , Output “tql” ;
The sample input :
10
Sample output :
tql
Cause analysis :
Solution :
#include <stdio.h>
int main()
{
printf("tql") ;
return 0;
}
problem C: Check in time
Problem description :
The author said it was time to write a sign in question for the freshman competition , But she doesn't want all freshmen to sign in ().
It is known that people who write questions like even numbers very much , So the author wants to choose from all the contestants Even number of students Let them sign in successfully .
existing n Contestants , The numbers are 1~n.
Now the author begins to choose m I'm a classmate .(m > 0)
If selected m The number of students is even , She will regard this as a good plan ; If it's odd , Is a bad plan .
Now the author wants to know the difference between the good plan and the bad plan .
Input :
An integer n, Represents the number of participants .(n <= 1e6)
Output :
Output the difference between good scheme and bad scheme .
The sample input :
4
Sample output :
-1
Cause analysis :
The sum of the coefficients of the odd term is C(n,1)+C(n,3)+C(n,5)...... = The sum of the coefficients of the even term C(n,0)+C(n,2)+C(n,4)......
And the title requires C(n,2)+C(n,4)...... - [ C(n,1)+C(n,3)+C(n,5)...... ]
namely Even items are missing C(n,0) That is, the final result is -1
Solution :
#include <stdio.h>
int main()
{
printf("-1\n") ;
return 0;
}
problem D: Dinner time
Problem description :
Small R As a senior cook , Every time he would seize every minute to buy all the things he wanted .
It's a small day R The things I want to buy are n Kind of , Buy this n The time of waiting in line for these kinds of things is a1 , a2 , a3 ... an ;
because , Small R Another very lazy person , He At most, I can only buy two kinds of things at the same time , also , What he needs to buy Come back before you finish , Otherwise, he has to queue up again .
for example , The time to buy cake is 15min, The time to buy drinks is 10min, The time to buy snacks is 4min, Small R You can buy a cake , Use the waiting time to buy drinks ; Although after buying drinks , also 5min You can buy snacks , But to simplify the problem , Small R I won't buy snacks , But go back and wait until the cake is ready , He will buy snacks again , such , He saved time to buy drinks alone , The total time is 15min+4min=19min;
Another example is , The time to buy cake is 15min, The time to buy drinks is also 15min, When he went to buy a cake , At the same time, he can't buy drinks , Because he is not satisfied with coming back before the cake is ready , So the total time is 30min.
Small R He is a very clever person , So he will use his wisdom , Find what you need to buy these things The shortest time .
Please calculate , Smart little girl R Buy everything he wants , The shortest time taken .
Input :
One line, one integer n ( n <= 1000 ), For little R The number of things you want to buy .
n It's an integer a1 , a2 , a3 ... an , No more than 1000;
Output :
One line, one integer , Represents the shortest time .
The sample input :
5 4 1 5 2 3
Sample output :
9
Cause analysis :
1. If the number of data is odd , You need to deal with the last number in particular ( The last number after sorting , That is, the minimum number )
namely a[n]=0; Of course, even numbers do not affect .
2. ans+=a[i]; Put it in the second for front , otherwise If the data is
3
5 5 5
Only output 5 That is, only the last one is added .
Solution :
#include<bits/stdc++.h>
using namespace std;
int n,a[10000],b[10000];
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
int i,j,ans=0,mid;
cin>>n;
for(i=0;i<n;i++)
cin>>a[i];
a[n]=0;
sort(a,a+n,cmp);
for(i=0;i<n;i++)
{
if(b[i]==1)
continue;
else
{
ans+=a[i];
for(j=i+1;j<n+1;j++)
{
if(a[i]>a[j]&&b[i]!=1&&b[j]!=1)
{
b[i]=1;
b[j]=1;
break;
}
}
}
}
cout<<ans;
}
problem F: Weekly list
Problem description :
The list of weekly matches has come out ,21 The results of this year are really great .
Someone wants to choose from the freshman list m personal , Make them "winner" ;
therefore , Curious someone wants to know , The chosen one m What is the maximum sum of personal achievements .
therefore , She came up with a competition question , Let the freshmen calculate by themselves .
Input :
An integer n(n <= 1e6), It represents the number of freshmen participating in the freshman competition .
Next, enter in the order of the list n The grades of freshmen . Score no more than 100.
An integer t(t <= 1e6), Represents the number of times someone asked .
Next t It's an integer .
Output :
Every time I ask , Before giving m The sum of the scores of the freshmen .
The sample input :
5 10 7 5 4 3 2 1 3
Sample output :
10 22
Cause analysis :
1. exceed 1e6 The data of Out-of-service cin( Unless I / O flow is turned off ), Or use scanf
Solution :
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll s[1000050],n,a[1000050];
int main()
{
ll t,x;
scanf("%lld",&n);
for(int i=1;i<=n;i++)
{
scanf("%lld",&a[i]);
s[i]=s[i-1]+a[i];
}
scanf("%lld",&t);
while(t--)
{
scanf("%lld",&x);
printf("%lld\n",s[x]);
}
return 0;
}
problem H: Trigonometry
Problem description :
o H There are six sticks .
o H I like triangles very much , therefore , He wanted to know if he could use these six sticks to form two triangles ?
To make the problem easier , o H Give you the sticks in order from big to small , Please help him solve the problem .
Input :
Six numbers , Representative a H The length of six sticks .( The length is less than 100)
Output :
Can form a triangle , Output "Yes" ;
conversely , Output "No" ;
The sample input :
1 1 1 1 1 1
Sample output :
Yes
Cause analysis :
The idea is basically right , Is to finally find the remaining three sticks There is something wrong with your thinking , You can directly put the subscript not equal to i,j,k The data of is stored in another array .
Solution :
1. Save the remaining number in another array ( Simple method )
#include <iostream>
#include <cstdio>
int is_right(int a , int b , int c)
{
if(c+b > a)
return 1 ;
return 0 ;
}
int main()
{
int a[10] ;
for(int i = 0 ; i < 6 ; i++)
scanf("%d", &a[i]) ;
int flag = 0 ;
for(int i = 0 ; i < 6 ; i++)
for(int j = i+1 ; j < 6 ; j++)
for(int k = j+1 ; k < 6 ; k++)
{
int b[5] ;
int c = 0 ;
for(int p = 0 ; p < 6 ; p++)
if(p != i && p != j && p != k)
b[c++] = a[p] ;
if(is_right(a[i] , a[j] , a[k])==1 && is_right(b[0] , b[1] , b[2])==1)
{
flag = 1 ;
break ;
}
}
if(flag == 0)
printf("No\n") ;
else
printf("Yes\n") ;
return 0 ;
}
2. Direct use of 3 individual for Find the remaining three
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
int a[7],i,j,k;
for(i=0;i<6;i++)
cin>>a[i];
for(i=0;i<6;i++)
{
for(j=i+1;j<6;j++)
{
for(k=j+1;k<6;k++)
{
if(a[k]+a[j]>a[i])
{
int x,y,z;
for(x=0;x<6;x++)
{
for(y=x+1;y<6;y++)
{
for(z=y+1;z<6;z++)
{
if(x!=i&&x!=j&&x!=k&&y!=i&&y!=j&&y!=k&&z!=i&&z!=j&&z!=k)
{
if(a[y]+a[z]>a[x])
{
cout<<"Yes";
return 0;
}
}
}
}
}
}
}
}
}
cout<<"No";
return 0;
}
Partial reprint cx Student sister %%%cx Gather together
2021HAUT_ Freshman week lcx Special field ( 3、 ... and )_lichenx_ The blog of -CSDN Blog
边栏推荐
- 软件测试 -- 0 序
- MySQL数据库(一)
- Lua GBK and UTF8 turn to each other
- Ue4/ue5 illusory engine, material chapter, texture, compression and memory compression and memory
- Simple HelloWorld color change
- Download and use of font icons
- BUUCTF MISC
- 小程序直播+電商,想做新零售電商就用它吧!
- Bubble sort summary
- Under the national teacher qualification certificate in the first half of 2022
猜你喜欢
Remote upgrade afraid of cutting beard? Explain FOTA safety upgrade in detail
Double pointer Foundation
《动手学深度学习》学习笔记
Unity ugui source code graphic
Reverse one-way linked list of interview questions
SAP-修改系统表数据的方法
Shell Sort
[转]MySQL操作实战(三):表联结
Optimization scheme of win10 virtual machine cluster
支持多模多态 GBase 8c数据库持续创新重磅升级
随机推荐
[转]MySQL操作实战(三):表联结
YOLOv5添加注意力機制
win10虚拟机集群优化方案
A preliminary study of sdei - see the essence through transactions
cocos_ Lua listview loads too much data
Pause and resume of cocos2dx Lua scenario
Bucket sort
Learning notes of "hands on learning in depth"
Transport connection management of TCP
GBase数据库助力湾区数字金融发展
Collapse of adjacent vertical outer margins
[to be continued] [UE4 notes] L1 create and configure items
Ue4/ue5 illusory engine, material chapter, texture, compression and memory compression and memory
[binary search] 34 Find the first and last positions of elements in a sorted array
win下一键生成当日的时间戳文件
[to be continued] I believe that everyone has the right to choose their own way of life - written in front of the art column
Haut OJ 1316: sister choice buys candy III
小程序直播+電商,想做新零售電商就用它吧!
[turn to] MySQL operation practice (III): table connection
十年不用一次的JVM调用