1.随机数
原题:
解题思路:
求出输入值中的最大值,从这个数输出到6即可
AC代码:
#include<bits/stdc++.h> #define ll long long using namespace std; int x,y; int main(){ freopen("random.in","r",stdin); freopen("random.out","w",stdout); cin>>x>>y; for(int i=max(x,y);i<=6;i++)cout<<i<<' '; return 0; }
2.鼓掌
原题:
解题思路:
求出lcm(x,y)后,计算一组的鼓掌时间,计算答案
AC代码:
#include<bits/stdc++.h> #define ll long long using namespace std; ll x,y,n,ans=0; ll gcd(ll a,ll b){ if(!b)return a; return gcd(b,a%b); } ll lcm(ll a,ll b){return a/gcd(a,b)*b;} int main(){ freopen("clap.in","r",stdin); freopen("clap.out","w",stdout); cin>>x>>y>>n; ll q=lcm(x,y); ans+=n/q*(q/x+q/y-1); ans+=(n%q/x)+(n%q/y); cout<<ans; return 0; }
3.统计成绩
原题:
解题思路:
记录每个学科的平均分,记录每个学生的成绩,统计答案
AC代码:
#include<bits/stdc++.h> #define ll long long using namespace std; const int N = 1e2+5; struct stud{ int a[25],sum; }stu[N]; struct classm{ int sum; double Mscor; }classma[25]; int n,m; int main(){ freopen("count.in","r",stdin); freopen("count.out","w",stdout); cin>>n>>m; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ cin>>stu[i].a[j]; classma[j].sum+=stu[i].a[j]; } } for(int i=1;i<=m;i++)classma[i].Mscor=classma[i].sum*1.0/n; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(classma[j].Mscor<=stu[i].a[j])stu[i].sum++; } cout<<stu[i].sum<<'\n'; } return 0; }
4.金币
原题:
解题思路:
这道题最大的n是999999999999999999,不可以暴力枚举,肯定超时,那么就要选择二分答案的方法,L=1,R=4000000000,去计算金币数,来求得天数,最后L就是答案
AC代码:
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> using namespace std; long long n,l=0,r=4000000000,mid,s,k,t; int main(){ cin>>n; while(l<=r){ mid=(l+r)/2; k=mid/7;t=mid%7; s=7*k*(k+1)/2+(k+1)*t; if(s<n)l=mid+1; else if(s>n)r=mid-1; else break; } cout<<l; return 0; }
标签:std,试题,青岛市,int,ll,long,2019,freopen,include From: https://www.cnblogs.com/zhanghx-blogs/p/17365387.html