奋斗群群赛---6
来源:互联网 发布:电脑桌面工作便签软件 编辑:程序博客网 时间:2024/06/05 05:53
奋斗群群赛—6
- 奋斗群群赛6
- T1Fraction
- 题目位置
- 题意
- AC代码
- 小反思
- T2Maxim Buys an Apartment
- 题目位置
- 题意
- AC代码
- 小反思
- T3Planning
- 题目位置
- 题意
- AC代码
- 小反思
- 反思
- T1Fraction
T1:Fraction
题目位置:
T1所在位置
题意:
即给你一个数字n,让你找到a,b使得a+b=n而且a,b互质,求a的最大情况!
AC代码:
#include <bits/stdc++.h>using namespace std;int gcd(int x,int y){ if(y==0) return x; return gcd(y,x%y);}int main(){ int n; cin>>n;// cout<<gcd(18,27)<<endl; for(int i=n/2; i>=1; i--) { int j=n-i; if(gcd(i,j)==1) { cout<<i<<" "<<j<<endl; return 0; } }}
小反思:
主要就是一个gcd递归函数的使用考研!
T2:Maxim Buys an Apartment
题目位置:
T2所在位置
题意:
只要就是有n所房子,有k的房子已经被人住了,而我想要与别人相邻,而且房子还没有出租的情况,问最多有几种选择和最少有几种选择?
比如(6,3) 最小情况是1,2,3被卖了,而自己只有4住,而最多就是1,3,5被卖了,而自己可以住2,4,6!于是输出1,3
AC代码:
#include <bits/stdc++.h>using namespace std;int main(){ long long int n,k; cin>>n>>k; if(n<=k) { cout<<0<<" "<<0<<endl; return 0; } if(k==0) { cout<<0<<" "<<0<<endl; return 0; } else { cout<<1<<" "; if(3*k<=n) cout<<2*k; if(3*k>n) cout<<n-k; return 0; }}
小反思:
主要是3*10^9会爆int的范围,所以就一直没有过,应该考虑数据的范围才好!
还有就是k=0,时是未有房子可以买的!
T3:Planning
题目位置:
T3题目所在
题意:
主要讲了有n架飞机,第i架是在imin起飞的,但是现在出现了故障,导致k分钟前都不能够起飞,这样的话每架飞机有延误而花费的费用,为1分钟的超时价格,让你求最小的花费!
利用堆来做会十分快捷!
AC代码:
#include <bits/stdc++.h>using namespace std;#define ll long longconst int N=300005;int a[N],air[N];priority_queue<pair<ll,ll> > airport;int main() { int n,k; cin>>n>>k; long long int tot=0; for(int i=1; i<=n; i++) cin>>a[i]; for(int i=1; i<=k; i++) airport.push(make_pair(a[i],i)); for(int i=k+1; i<=n+k; i++) { if(i<=n) airport.push(make_pair(a[i],i)); pair<ll,ll>plane=airport.top(); airport.pop();//¿ªÊ¼ÕûÀí tot+=plane.first*(i-plane.second); air[plane.second]=i; } cout<<tot<<endl; for(int i=1; i<=n; i++) cout<<air[i]<<" "; return 0;}
小反思:
学会优先队列是关键啊!
反思:
1.学会查找数据范围会不会超!
2.学会堆!
阅读全文
0 0
- xjoi奋斗群群赛6
- 奋斗群群赛---6
- 奋斗群群赛6总结与心得
- xjoi奋斗群群赛2
- 奋斗群群赛---3 渐入佳境
- xjoi奋斗群群赛3
- xjoi奋斗群群赛4
- 奋斗群群赛---4
- xjoi奋斗群群赛5
- 奋斗群群赛---5
- 奋斗群群赛---7
- xjoi奋斗群群赛7
- xjoi奋斗群群赛8
- 奋斗群群赛---8
- 奋斗群群赛---9
- 奋斗群群赛11---筚路蓝缕
- 奋斗群群赛---12
- xjoi奋斗群群赛10
- POJ 3352 Road Construction (缩点)
- 苹果果然再次推送iOS 11第十个测试版 在iphone8上预装应该是定了
- 数据库二:深入理解DB2索引(Index)
- css3 阴影
- python基础
- 奋斗群群赛---6
- css3 倒影
- css3 渐变
- Android_XListView请求网络数据
- spring学习十一 通过注解配置bean
- python3语言的基础学习
- 笔记本开机小键盘自动启动
- [IOS笔记]plist创建和使用
- Android_请求网络数据