SDNU_ACM_ICPC_2020_Winter_Practice_4th
H - Triangle
思路:
用了斐波那契数列,因为数列中的任意三数都无法组成三角形,所以将1,2,3,,,n变成斐波那契数列就符合条件;
#include <iostream>
using namespace std;
int main()
{
int t,n,a,sum=,f[]={,,,,,};
cin>>t;a=t; while(t--)
{
cin>>n;
sum=;
for(int i=;i<;i++)
{
if(n>=f[i])
sum++;
}
cout<<"Case #"<<a-t<<": ";
cout<<n-sum;
cout<<endl;
} }
K - Reverse a Substring
思路:先将字符串升序排序,与原字符串比较大小,若大于等于原字符串,则说明原字符串已经是字典序最小的排列方式;否则,逐一比较两字符串中元素,不同者,输出;
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main()
{
int n;
char s[],m[];
cin>>n;
for(int i=;i<n;i++)
{
cin>>s[i];
m[i]=s[i];
}
sort(m,m+n);
for(int i=;i<n;i++)
{
if(m[i]<s[i])
{
cout<<"YES"<<endl<<i+<<" ";
for(int j=i+;j<n;j++)
{
if(s[j]==m[i])
{
cout<<j+<<endl;
return ;
}
}
}
}
cout<<"NO"; }
L - Game with Telephone Numbers
注意:第11行,s[i]=='8' 而不是 s[i]==8
#include <iostream>
#include <string>
using namespace std;
int main()
{
int n,t=;
string s;
cin>>n>>s;
for(int i=;i<=n-;i++)
{
if(s[i]=='')
{
t++;
}
}
if(t<=(n-)/)
cout<<"NO";
else
cout<<"YES";
}
I - Birthday Paradox
长知识了

因此,所有人生日不同的概率为(天数-1)/天数*(天数-2)/天数*....(天数-n+1)/n;
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
int main()
{
int t,n,K;
cin>>t;
int a=;
while(t--)
{
double sum=1.0;
cin>>n;
for(int i=;i<=n;i++)
{
sum*=(n-i)*1.0/n;
if(sum<=0.5)
{
K=i;
break;
}
}
cout<<"Case "<<a++<<": "<<K<<endl;
}
}
SDNU_ACM_ICPC_2020_Winter_Practice_4th的更多相关文章
随机推荐
- Paper: ModelarDB
Problem: how to store and querry massive amounts of high quality sensor data ingested in real-time f ...
- 未能加载文件或程序集“Autofac.Integration.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da”或它的某一个依赖项。找到的程序集清单定义与程序集引用不匹配。 (异常来自 HRESULT:0x80131040)
是因为web.config中dependentAssembly结点下的版本号和当前引用的程序集的版本号不一致!
- 【蓝桥杯/算法训练】Sticks 剪枝算法
剪枝算法 大概理解是通过分析问题,发现一些判断条件,避免不必要的搜索.通常应用在DFS 和 BFS 搜索算法中:剪枝策略就是寻找过滤条件,提前减少不必要的搜索路径. 问题描述 George took ...
- Entity Framework 简介
Entity Framework Entity Framework 的全称为 ADO.NET Entity Framework,简称 EF. 1.与 ADO.NET 的关系 Entity F ...
- python写excel总结
废话不说,直接上代码:import xlrd import xlwt # 读excel然后写到mysql的套路def updata_info(): book = xlrd.open_workbook( ...
- vue-cli的版本查看及vue2.x和vue3.0的区别
链接:https://www.cnblogs.com/wyongz/p/11505048.html 链接2:https://blog.csdn.net/weixin_37745913/article/ ...
- data-dismiss="modal"
提交按钮不加: 加上则不会出现提示,直接关闭弹出框 <div class="modal fade" id="myModal" tabindex=" ...
- 1.什么是springboot
什么是spring? Spring是一个开源框架,2003 年兴起的一个轻量级的Java 开发框架,作者:Rod Johnson . Spring是为了解决企业级应用开发的复杂性而创建的,简化开发. ...
- 【Python】数值运算函数
- jquery点击添加样式,再次点击移除样式
$("#divSetting").on("click", function () { $(this).toggleClass("open") ...