NCD 2019部分题解

  • A
  • B
  • C
  • D
  • E
  • F
  • G
  • H
  • J
  • K
  • L
  • M

A

A - Hasan the lazy judge

B

B - Let me sleep

C

C - Hasan and his lazy students
题目大意:求最长上升子序列的长度和个数
思路:LIS的模板 设f[i][j]数组用来表示以i结尾,长度为j的上升子序列数量

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e3 + 10;
const int mod = 1e9 + 7;
int t, n;
int a[N], dp[N]; // dp[i]表示以i结尾的最长上升子序列的长度
ll f[N][N];      // f[i][j]表示以i结尾,长度为j的上升子序列的总个数
int main()
{cin >> t;while (t--){cin >> n;int mx = 1;memset(f,0,sizeof(f));for (int i = 0; i < n; i++){cin >> a[i];dp[i] = 1;f[i][1] = 1;for (int j = 0; j < i; j++){if (a[j] < a[i]){dp[i] = max(dp[i], dp[j] + 1);f[i][dp[j] + 1] = (f[i][dp[j] + 1] + f[j][dp[j]]) % mod;mx = max(mx, dp[i]);}}}ll ans = 0;for (int i = 0; i < n; i++)ans = (ans + f[i][mx]) % mod;cout << mx << ' ' << ans << endl;}system("pause");
}

D

D. Football Cup
(水题)

#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
int x,y,t;
int main()
{cin>>t;while(t--){cin>>x>>y;if(x>y) cout<<"Bashar\n";else if(x<y) cout<<"Hamada\n";else if(x==y) cout<<"Iskandar\n";}
}

E

E - Adnan and the Burned drivers

F

F - Research projects
(水)

#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
ll t,n,k;
int main()
{cin>>t;while(t--){cin>>n>>k;ll ans=(n-k)/6;if(6*ans<(n-k)) ans++;cout<<ans<<endl;}
}

G

G - Ali and the Breakfast

H

H - Mr. Hamra and his quantum particles
(并查集模板题)

#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 1e5+10;
int fa[N],ran[N];
int t,n,m,q;
void init()
{for(int i=0;i<N;i++)fa[i]=i,ran[i]=1;
}
int find(int x)
{if(x!=fa[x]) fa[x]=find(fa[x]);return fa[x];
}
void unit(int x,int y)
{x=find(x),y=find(y);if(x==y) return ;if(ran[x]<=ran[y]) fa[x]=y;else fa[y]=x;if(ran[x]==ran[y]) ran[x]++;
}
bool same(int x,int y)
{return find(x)==find(y);
}
int main()
{cin>>t;while (t--){cin>>n>>m>>q;init();string s="";for(int i=1;i<=m;i++){int x,y;cin>>x>>y;unit(x,y);}for(int i=1;i<=q;i++){int x,y;cin>>x>>y;if(same(x,y)) s+="1";else s+="0";}cout<<s<<endl;}
}

J

J- Bashar and daylight saving time

K

K- Masaoud LOVES PIZZAS
题意:求有多少个子段和不超过X
思路:预处理前缀和,对于满足的子段,每一个L端对应一个最大的R满足条件,那么小于R内的子段都满足条件,可以二分找一下R即可,最后结果为所有满足条件的子段数量和
代码

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
ll a[N], sum[N];
ll t, n, x;
int main()
{cin >> t;while (t--){cin >> n >> x;memset(sum, 0, sizeof(sum));for (int i = 1; i <= n; i++){cin >> a[i];sum[i] = sum[i - 1] + a[i];}ll ans = 0;for (int i = 1; i <= n; i++){int l = i, r = n, R = 0;while (l <= r){int mid = (l + r) / 2;if (sum[mid] - sum[i - 1] < x) l = mid + 1, R = mid;  else r = mid - 1;}ans += max(0, R - i + 1);}cout << ans << endl;}
}

L

L - Chemistry Exam
题目大意:求一个数二进制中1的个数

#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 1e5+10;
int a[N],b[N];
int t,n;
int jg(int x)
{int cnt=0;while (x){int m = x%2;if(m) cnt++;x/=2;}return cnt;
}
int main()
{cin>>t;while(t--){cin>>n;for(int i=1;i<=n;i++){cin>>a[i];b[i]=jg(a[i]);}for(int i=1;i<=n;i++)cout<<b[i]<<' ';cout<<"\n";}
}

M

M - NCD Salary
题目大意
思路:用log转换比较 特判一下B1,B2为0的情况。
代码

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
const int N = 1e5+10;
int t;
int b1,b2,p1,p2;
int main()
{cin>>t;while (t--){cin>>b1>>p1>>b2>>p2;if(b1==0||b2==0){if(b1==b2) cout<<"Lazy\n";else if(b1<b2) cout<<"Congrats\n";else cout<<"HaHa\n";}else{double x1 = p1*log(b1*1.0);double x2 = p2*log(b2*1.0);if(fabs(x1-x2)<=1e-6) cout<<"Lazy\n";else if(x1<x2) cout<<"Congrats\n";else cout<<"HaHa\n";}}
}

寒假训练2 (NCD 2019)相关推荐

  1. 牛客网平台常州大学新生寒假训练会试

    A-添加逗号 链接:https://www.nowcoder.net/acm/contest/78/A 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其 ...

  2. [XUPT]2020寒假训练---比赛专题

    比赛链接:https://vjudge.net/contest/357216 说明: 比赛难度正好符合寒假训练的同学.(有一两道可能一些同学做过,我们出题没考虑到sorry) 下面对题目进行解答一下. ...

  3. NEFU 大一寒假训练十二(set)2020.02.18

    Summary 可能是昨天的题少了一些,今天的题多了一堆,还疯狂TLE /(ㄒoㄒ)\~~ Information No. Title AC/Submit A 明明的随机数-set 60/101 B ...

  4. 寒假训练八(优先队列)2020.02.14(7题)

    寒假训练八(优先队列)id:530 Problem:A 买饭-优先队列 Description 林大食堂非常拥挤,得排队买饭,陈老师也是一样的! 有n个人在一个卖饭窗口前排队买饭,假如每个人买饭的时间 ...

  5. 一起开心2020蓝桥寒假训练(二)7-6 彩虹瓶 (25分)用到栈,队列

    一起开心2020蓝桥寒假训练(二)7-6 彩虹瓶 (25分) 彩虹瓶的制作过程(并不)是这样的:先把一大批空瓶铺放在装填场地上,然后按照一定的顺序将每种颜色的小球均匀撒到这批瓶子里. 假设彩虹瓶里要按 ...

  6. 寒假训练十(map,pair,string)2020.02.17(4题)

    寒假训练十(map) id:535 Problem:A 保龄球-map Description DL 算缘分算得很烦闷,所以常常到体育馆去打保龄球解闷.因为他保龄球已经打了几十年了,所以技术上不成问题 ...

  7. QLU寒假训练赛题解合集

    为了节省版面: 1.所有寒假训练赛题解都集中在这一篇里 2.所有题解代码都可以直接点击题目链接查看 0115 A题:签到,输出n+1 B题:签到,从左端点向右找一段和小于0的区间,再从右往左找 C题: ...

  8. 20200203DLUT寒假训练赛div2-简单搜索专场

    20200203DLUT寒假训练赛div2-简单搜索专场 :比赛地址 A - Find The Multiple 简单的dfs水题,主要是取10x和10x+1两种情况,并且注意函数存储数字必须得用un ...

  9. 2019级寒假训练-Java

    文章目录 选择题 单选题 编程题 7-1 整型数除法异常处理 (10 分) 7-2 使用HashMap实现查找功能 (10 分) 7-3 统计字母和空格出现的次数 (10 分) 7-4 自定义异常Ci ...

最新文章

  1. 【移动端DL框架】当前主流的移动端深度学习框架一览
  2. JavaFX技巧13:学习Modena CSS文件
  3. c中将数组传递给子函数_在C ++中将对象传递给Non-Member函数
  4. python有趣的函数_Python中有趣在__call__函数
  5. JDWP Transport dt socket failed to initialize
  6. 字段定义_联系人字段随需自定,知己知彼快速签单
  7. OpenSSL密码库算法笔记——第1章 大整数的基本运算
  8. tomcat未自动解压war包原因分析
  9. java怎么写脚本_一名资深牛人写的Java脚本编程指南
  10. 2018.10.31 NOIP模拟 一串数字(数论+贪心)
  11. Settings sync 配置与使用
  12. python中as是什么意思_python中“as”语句的含义是什么?
  13. UNIX环境高级编程(APUE)读书笔记
  14. html图片超出内容隐藏,图片按比例缩小,溢出超出DIV边框的内容自动隐藏方法!...
  15. 设计师:设计师知识储备(硬装、软装、榻榻米、马卡龙、地台、公共空间、玄关、闭水实验)之详细攻略
  16. 四川省着力打造三位一体服务平台,精准服务保障农民工
  17. 11.3 树的遍历:LDR,LRD,VLR 相关代码
  18. 【数据库】数据库基本知识
  19. 2021东三省数学建模竞赛a题
  20. NSIS检测.NET Framework并在线下载

热门文章

  1. 草图大师软件SketchUp下载附安装教程
  2. Python爬虫三国演义
  3. 学习记录 | SHT30温湿度传感器显示异常
  4. 麦当劳中国、星巴克中国、中国红牛、歌帝梵等企业发布动态 | 食品饮料新品...
  5. STM32的SysTick定时器记录一篇
  6. 【Bzoj3631】松鼠的新家
  7. Java_Spring_IoC
  8. 魅族PRO 5详细开启Usb调试模式的流程
  9. 就算没时光机,你也可以来这儿一窥未来世界
  10. 【vue2,3使用QRCode进行二维码的生成和下载】