蓝桥杯国赛五一训练赛(1)
蓝桥杯国赛五一训练赛(1)(链接)
问题 A: 费解的开关
3
00111
01011
10001
11010
1110011101
11101
11110
11111
1111101111
11111
11111
11111
11111
3
2
-1
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
string a[5];
string tp[5];
int dir[]={1,0,-1,0,1};
void switch_(int x,int y){ //转换(x,y)灯及其四周灯状态tp[x][y]^=1;for(int i=0;i<4;i++){int tx=x+dir[i];int ty=y+dir[i+1];if(tx>=0&&ty>=0&&tx<5&&ty<5) tp[tx][ty]^=1;}
}
bool check(){for(int i=0;i<5;i++)if(tp[4][i]=='0') return false;return true;
}
void solve(){int res=7,cnt;for(int i=0;i<5;i++) cin>>a[i];for(int k=0;k<(1<<5);k++){//枚举第一行的所有按法cnt=0;for(int i=0;i<5;i++) tp[i]=a[i];//备份for(int i=0;i<5;i++) if((1<<i)&k){switch_(0,i);cnt++;}for(int i=0;i<4;i++)for(int j=0;j<5;j++)if(tp[i][j]=='0'){cnt++;switch_(i+1,j);}if(check()) res=min(res,cnt);}if(res>6) res=-1;printf("%d",res);
}
int main()
{int n;cin>>n;while (n--){solve();printf("\n");}return 0;
}
问题 B: 最短Hamilton路径
接下来n行每行n个整数,其中第i行第j个整数表示点i到j的距离(一个不超过10^7的正整数,记为a[i,j])。
对于任意的x,y,z,数据保证 a[x,x]=0,a[x,y]=a[y,x] 并且 a[x,y]+a[y,z]>=a[x,z]。
输出
一个整数,表示最短Hamilton路径的长度。
样例输入
4
0 2 1 3
2 0 2 1
1 2 0 1
3 1 1 0
4
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int f[1<<20][20];
//f[i][j] = f[i-j][k] + mp[k][j]
int mp[20][20];
int main()
{int n;cin>>n;memset(f,0x3f,sizeof f);for(int i=0;i<n;i++)for(int j=0;j<n;j++)cin>>mp[i][j];f[1][0]=0; //起点路径长为0for(int i=0;i<1<<n;i++){ //枚举所有状态for(int j=0;j<n;j++){if((1<<j)&i){ //如果j点在i中,更新最短路径for(int k=0;k<n;k++){if((1<<k)&(i-(1<<j))){f[i][j]=min(f[i][j],f[i-(1<<j)][k]+mp[k][j]);}}}}}cout<<f[(1<<n)-1][n-1];return 0;
}
问题 C: IncDec Sequence
4
1
1
2
2
1
2
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{int n;cin>>n;vector<int>a(n);for(int &x:a) cin>>x;ll x=0,y=0;for(int i=n-1;i>0;i--) a[i]-=a[i-1];for(int i=1;i<n;i++)if(a[i]>0) x+=a[i];else y-=a[i];if(x>y) swap(x,y);cout<<y<<'\n'<<y-x+1;return 0;
}
问题 D: Best Cow Fences
10 6
6 4 2 10 3 8 5 9 4 1
6500
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N = 1e5+5;
const double eps = 1e-5;
int n,l;
int a[N];
double b[N];
bool check(double m){for(int i=1;i<=n;i++) b[i]=b[i-1]+a[i]-m;double minx=0; //minx记录最小的b[i],使得b[j]-b[i]尽可能大for(int i=0,j=l;j<=n;i++,j++){minx=min(minx,b[i]);if(b[j]-minx>=0) return true;}return false;
}
int main()
{cin>>n>>l;for(int i=1;i<=n;i++) cin>>a[i];double l=0,r=1e6;while (l+eps<r){double m=(l+r)/2;if(check(m)) l=m;else r=m;}cout<<(int)(r*1000);return 0;
}
问题 E: SOLDIERS
5
1 2
2 2
1 3
3 -2
3 3
8
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N = 1e5+5;
const double eps = 1e-5;
int n;
int x[N],y[N];
int main()
{cin>>n;for(int i=0;i<n;i++) cin>>x[i]>>y[i];sort(x,x+n);sort(y,y+n);int res=0;int md=y[n/2];for(int i=0;i<n;i++) {res+=abs(y[i]-md);x[i]-=i;}sort(x,x+n);md=x[n/2];for(int i=0;i<n;i++) res+=abs(x[i]-md);cout<<res;return 0;
}
问题 F: To the Max
0 -2 -7 0
9 2 -6 2
-4 1 -4 1
-1 8 0 -2
is in the lower left corner:
4
0 -2 -7 0
9 2 -6 2
-4 1 -4 1
-1 8 0 -2
15
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N = 1e5+5;
const double eps = 1e-5;
int n;
int a[105][105];
int main()
{int n;cin>>n;for(int i=1;i<=n;i++)for(int j=1;j<=n;j++){cin>>a[i][j];a[i][j]+=a[i-1][j];}int res=-1e9;for(int i=1;i<=n;i++){for(int j=i;j<=n;j++){int mp=0;for(int k=1;k<=n;k++){int tp=a[j][k]-a[i-1][k];if(mp>=0) mp+=tp;else mp=tp;res=max(res,mp);}}}cout<<res;return 0;
}
问题 G: Task
1 2
100 3
100 2
100 1
1 50004
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N = 1e5+5;
const double eps = 1e-5;
struct nd
{int x,y;bool operator<(nd t){if(x==t.x) return y>t.y;return x>t.x;}
}task[N],ma[N];
int main()
{int n,m;multiset<int>rs;ll res,cnt;while (cin>>n>>m){rs.clear();res=0,cnt=0;for(int i=0;i<n;i++) cin>>ma[i].x>>ma[i].y;for(int i=0;i<m;i++) cin>>task[i].x>>task[i].y;sort(ma,ma+n);sort(task,task+m);int j=0;for(int i=0;i<m;i++){while (j<n&&ma[j].x>=task[i].x) rs.insert(ma[j++].y);auto t=rs.lower_bound(task[i].y);if(t!=rs.end()){cnt++;res+=500*task[i].x+task[i].y*2;rs.erase(t);}}cout<<cnt<<' '<<res<<'\n';}return 0;
}
问题 H: Largest Rectangle in a Histogram
7 2 1 4 5 1 3 3
4 1000 1000 1000 1000
0
8
4000
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N = 1e5+5;
const double eps = 1e-5;
int main()
{int n;vector<pair<ll,ll>>stk;ll x,h,res;pair<ll,ll>tp;while (cin>>n,n){res=0;stk.clear();for(int i=0;i<n;i++){scanf("%lld",&x);if(stk.empty()) stk.push_back({x,1});else{h=0;while (stk.size()){tp=stk.back();if(tp.first<=x) break;stk.pop_back();h+=tp.second;res=max(res,h*tp.first);}stk.push_back({x,h+1}); }}h=0;while (stk.size()){tp=stk.back();stk.pop_back();h+=tp.second;res=max(res,h*tp.first);}printf("%lld\n",res);}return 0;
}
问题 I: 邻值查找
3
1 5 3
4 1
2 1
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N = 1e5+5;
const double eps = 1e-5;
pair<ll,int>a[N],res[N];
int l[N],r[N],p[N];
int main()
{int n;cin>>n;for(int i=1;i<=n;i++){cin>>a[i].first;a[i].second=i;}sort(a+1,a+n+1);a[0].first=-1e10;a[n+1].first=1e10;for(int i=1;i<=n;i++){l[i]=i-1;r[i]=i+1;p[a[i].second]=i;}for(int i=n;i>1;i--){int pos=p[i];int lf=l[pos],rt=r[pos];ll lv=a[pos].first-a[lf].first;ll rv=a[rt].first-a[pos].first;if(lv>rv) res[i]={rv,a[rt].second};else res[i]={lv,a[lf].second};l[rt]=lf;r[lf]=rt;}for(int i=2;i<=n;i++) printf("%lld %d\n",res[i].first,res[i].second);return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N = 1e5+5;
const double eps = 1e-5;
int main()
{int n;scanf("%d",&n);ll a;set<pair<ll,int>>res;res.insert({-1e10,-1});res.insert({1e10,1e5});for(int i=1;i<=n;i++){scanf("%lld",&a);auto t=res.insert({a,i}).first;//insert()会返回插入后元素的迭代器if(i!=1){auto l=t,r=t;l--;r++;ll lv,rv;lv=t->first-l->first;rv=r->first-t->first;if(rv<lv) printf("%lld %d\n",rv,r->second);else printf("%lld %d\n",lv,l->second);}}return 0;
}
蓝桥杯国赛五一训练赛(1)相关推荐
- 蓝桥杯国赛知识点汇总
蓝桥杯国赛备赛总结知识点,以老师给的为原型,添加自己理解,供大家参考,后期不定时更新. 基础 1.熟练掌握API1.8常用方法 2.大数(高精度)加减乘除 3.并查集 模板: public class ...
- 蓝桥杯评分标准_新闻 | 人工智能学院创新创业实践中心开展蓝桥杯国赛经验分享会...
为让各位蓝桥杯国赛选手以饱满精力迎接接下来的比赛,天津科技大学人工智能学院创新创业实践中心邀请到计算机科学与技术专业教研室主任吴江红老师为各位蓝桥杯国赛选手分享经验,提高选手们的应试应赛能力. 吴江红 ...
- 2020年第十一届蓝桥杯 - 国赛 - Python大学组 - H.答疑
题目链接 Ideas 2020年第十一届蓝桥杯 - 国赛 - Python大学组 - H.答疑 Code Python if __name__ == '__main__':n = int(input( ...
- 2020年第十一届蓝桥杯 - 国赛 - Java研究生组 - F.循环小数
2020年第十一届蓝桥杯 - 国赛 - Java研究生组 - F.循环小数 在线评测 Ideas 对于一个纯循环小数,假设循环节为l,则小数为0.llll-,转换为分数就是 l / (10 ** n ...
- 第十一届蓝桥杯国赛题目
以下是第十一届蓝桥杯国赛题目,供大家学习参考(提取码失效可以评论我) 百度云: 链接: https://pan.baidu.com/s/1g1o-px-RUVoXLLhRDS8cXQ 提取码: fgf ...
- 2022年十三届蓝桥杯国赛(C/C++大学B组)个人题解
2022年十三届蓝桥杯国赛(C/C++大学B组)个人题解 更新:成绩出来了,估分50分左右,最后拿了个国二,还差点到国一,有点出乎意料,挺满意了挺满意了. 去年国赛基本都是暴力,最后国三都没拿到(我是 ...
- 第十二届蓝桥杯国赛真题+题解 Python
文章目录 写在前面 试题A:带宽 试题 B: 纯质数 试题C: 完全日期 试题D: 最小权值 试题 E: 大写 试题 F: 123 试题 G: 冰山 试题 H: 和与乘积 试题 I: 二进制问题 试题 ...
- 蓝桥杯国赛C++A组B组题解整理(第八、七、六、五、四届)
[写在前面的话19.04.04] 今年省赛的结果出的意外得快,有很多小伙伴来和我分享他们进了省一的喜悦,并问我啥时候更新国赛题解,emmm--不是我不想更新,实在是抽不出时间,有缘再更--虽然不更新题 ...
- 第十三届蓝桥杯国赛真题 PythonB组 复盘以及获奖感言(国一!!!)
第十三届蓝桥杯国赛真题 PythonB组 复盘以及获奖感言(国一) 文章目录 第十三届蓝桥杯国赛真题 PythonB组 复盘以及获奖感言(国一)
最新文章
- 查看Eclipse版本
- java设计模式之为别人做嫁衣----代理模式
- server.mapPath(.mdb)
- unicode字符串操作函数 vc
- 制定统一业务逻辑基础规则
- 并不是所有的 Github 项目写在简历上都加分
- background-origin:规定 background-position 属性相对于什么位置来定位
- Linux:为什么那么多人讨厌systemd?
- linux 下 maven 安装配置
- 僵化封闭果然是主流——评华为会员资格被暂停
- java c md5 疯_JAVA md5把我气到疯的代码,天哪,神呀,我的C# 啊。
- C语言程序设计(第三版)何钦铭著 习题6-3
- 加拿大计算机硕士留学移民,加拿大硕士留学移民深度解析,纯干货
- 李开复:非一流学校学生的出路-李开复经验集-IT人物-酷勤网
- FPGA CDC跨时钟域设计学习(一)亚稳态
- 手指 (shou zhi)
- IT编程自学与培训的优缺点对比!
- android gradle lint,Android Lint
- JAVA毕设项目个性化推荐的扬州农业文化旅游管理平台(java+VUE+Mybatis+Maven+Mysql)
- outlook 2003 使用技巧
热门文章
- 初学linux(-)
- VC6link卡死解决办法
- [转]Flex 处理bmp图片as
- 面对不同种类的处理结果——result type=
- 【AI简报20210730期】黑芝麻A1000 Pro自动驾驶芯片流片成功、地平线征程 5 芯片发布...
- wps如何自己制作流程图_wps怎么制作流程图【搞定教程】
- 金融系统性风险的网络模型
- 新玺配资:股票市场中的配股是什么意思
- 结构建模设计——Solidworks软件之草图几何关系绘制与草图编辑功能总结(裁剪实体、转换实体引用、等距实体)
- python云计算好学吗_没有基础,可以学云计算专业吗,学起来是不是很难,?