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的更多相关文章

随机推荐

  1. classification tips 01: npy file

    numpy array storation; npy/npz file. 文件存取的格式:二进制和文本.二进制格式的文件又分为NumPy专用的格式化二进制类型和无格式类型. numpy文件存取-npz ...

  2. QT5.1+中文乱码问题

    原文连接:https://blog.csdn.net/liyuanbhu/article/details/72596952 QT中规定 QString 的 const char* 构造函数是调用 fr ...

  3. 线程同步器CountDownLatch

    Java程序有的时候在主线程中会创建多个线程去执行任务,然后在主线程执行完毕之前,把所有线程的任务进行汇总,以前可以用线程的join方法,但是这个方法不够灵活,我们可以使用CountDownLatch ...

  4. python面试的100题(10)

    18.反转一个整数,例如-123 --> -321 class Solution(object): def reverse(self,x): if -10<x<10: return ...

  5. Virtual Judge POJ 1328 Radar Installation

    贪心 #include<algorithm> #include<iostream> #include<cstdio> #include<cmath> u ...

  6. php设计模式之责任链模式实现举报功能实例代码

    html <html> <head> <meta charset="UTF-8"> <title>责任链模式</title&g ...

  7. Led Candle Light - Safe, Cost-Effective, Versatile, Realistic Flame Lighting

    Candles have been used to remove light for centuries, but it took hundreds of years to make better c ...

  8. scrapy 框架基本使用

    scrapy简介: Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架. 其可以应用在数据挖掘,信息处理或存储历史数据等一系列的程序中.其最初是为了页面抓取 (更确切来说, 网络抓取 ...

  9. 劳动人民万岁(拒绝惰性)------- 浅谈迭代对象(Iterable) 迭代器(Iterator)

    一.前戏 问题:如果一次抓取所有城市天气 再显示,显示第一个城市气温时有很高的延时,并且很浪费储存空间 解决方案:以“用时访问”策略,并且能把说有城市气温封装到一个对象里,可用for一句进行迭代 二. ...

  10. 使用表单对象时,报错 form is undefine

    先看例子 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <ti ...