医院
include <bits/stdc++.h>
using namespace std;
int main()
{
int n=0;
//灵活使用C的输入输出→减时间提效率(头文件<stdio.h>)
scanf("%d",&n);
long long x=0,y=0;
double d=0,t=0;
for(int i=0; i<n; i++)
{
scanf("%lld%lld",&x,&y);
t=sqrt(x*x+y*y);
if(i==0)
d=t;
else{
if(t<d) d=t;
}
}
printf("%.6lf\n",d);//控制数字精度6位小数
//C++控制:cout<<fixed<<setprecision(6)<<d<< endl;(头文件<iomanip>)
return 0;
}
概率论
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long n=0;//注意数据范围
double p=0.0;
cin>>n>>p;
n=n*(1-p);
cout<<n;
return 0;
}
学妹的高数题
#include <iostream>
using namespace std;
int main()
{
int p;
cin>>p;
if(p>1)
cout<<"infinity";
else if(p<1) cout<<"0\n";
else if(p=1) cout<<"1\n";
return 0;
}
1e7神机
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s1,s[3]= {"codeforces","nowcoder","zzulioj" };
char s2[10];//注意题目x的范围
cin>>s1;
scanf("%s",s2);//好用极了
int m=0;
while(s2[m]) m++;
//比较对象为char用strcmp(c1,c2)
//比较对象为string用==如下、或compare()函数:s1.compare(s2)
if(s1==s[0]||s1==s[1])
{
if(m>3||s2[2]>'9')
cout<<"Time Limit Exceeded";
else
cout<<"Accepted";//也可以printf("Accepted\n")
}
else if(s1==s[2])
{
if(m>3||s2[2]>'7')
cout<<"Time Limit Exceeded";
else
cout<<"Accepted";
}
else
cout<<"no response";
return 0;
}
大嘴猫吃金币
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int a[N];
int main()
{
int n;
cin>>n;
long long m=0,s=0;
for(int i=0;i<n;i++)
{
cin>>a[i];
if(s+a[i]>=0) s+=a[i];
else s=0;//维护s最大值
m=m<s?s:m;
}
cout<<m;
return 0;
}
通项公式
解法一(map&数组)
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
typedef long long ll;
map<ll,ll>mp;
int main()
{
int a[5];
long long n,s=0;
for(int i=1; i<N; i++)
{
mp[(ll)(i+1)*(i+1)]=i;//强制类型转换很关键
}
for(int i=1; i<N; i++)
{
n=(ll)i*(2*i-1);
if(mp[n]){
a[s]=n;
s++;
}
}
int n;
cin>>n;
cout<<v[n-1]<<endl;
return 0;
}
//解法二(map&vector)
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
typedef long long ll;
map<ll,ll>mp;
vector<ll>v;
int main()
{
for(int i=1; i<N; i++){
mp[(ll)(i+1)*(i+1)]=i;
}
for(int i=1; i<N; i++){
ll t=(ll)i*(2*i-1);
if(mp[t]) v.push_back(t);
}
int n;
cin>>n;
cout<<v[n-1]<<endl;
return 0;
}
map函数
vector函数