蓝桥杯备战刷题one(自用)

1.被污染的支票

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
int main()
{
  int n;
  cin>>n;
  vector<int>L;
  map<int,int>mp;
  bool ok=0;
  int num;
  for(int i=1;i<=n;i++)
  {
    cin>>num;
    if(mp[num]==1)ok=1;
    else
    {
      mp[num]=1;
      L.push_back(num);
    }
  }
  sort(L.begin(),L.end());
  int x=L.back()*2;//?????
  vector<int>L2;
  for(int i=2;i<x;i++)
  {
    if(x%i==0)L2.push_back(i);
  }
  if(L!=L2)ok=1;
  if(ok)
  {
    cout<<-1<<endl;
  }
  else
  {
    cout<<x<<endl;
  } 
  return 0;
}

2.日期统计

#include <iostream>
#include <vector>
#include <map>
using namespace std;
int main()
{
  int ans=0;
  int num[100]={5, 6, 8, 6, 9, 1, 6, 1, 2, 4,
                9, 1, 9, 8, 2, 3, 6, 4, 7, 7, 
                5, 9, 5, 0, 3, 8, 7, 5, 8, 1,
                5, 8, 6, 1, 8, 3, 0, 3, 7, 9,
                2, 7, 0, 5, 8, 8, 5, 7, 0, 9,
                9, 1, 9, 4, 4, 6, 8, 6, 3, 3,
                8, 5, 1, 6, 3, 4, 6, 7, 0, 7,
                8, 2, 7, 6, 8, 9, 5, 6, 5, 6,
                1, 4, 0, 1, 0, 0, 9, 4, 8, 0,
                9, 1, 2, 8, 5, 0, 2, 5, 3, 3};
  int days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
  for(int mon=1;mon<=12;mon++)
  {
    for(int day=1;day<=days[mon];day++)
    {
      int temp[8]={2,0,2,3,mon/10,mon%10,day/10,day%10};
      int k=0;
      for(int i=0;i<100;i++)
      {
        if(num[i]==temp[k])
        {
          k++;
        }
        if(k==8)
        {
          ans++;
          break;
        }
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

3.01串的熵

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
  int n=23333333;
  for(int i=0;i<=n/2;i++)//0的次数
  {
    double a=(i*1.0)/n;
    double b=((n-i)*1.0)/n;
    double ans=0;
    ans-=(a*log2(a)*i+b*log2(b)*(n-i));
    if(fabs(ans-11625907.5798)<0.0001)
    {
      cout<<i<<endl;
      break;
    }
  }
  return 0;
}

(注意浮点数,double,以及比较大小时使用1e-4) 

4.冶炼金属

评论 30
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值