【01串的熵】
https://www.lanqiao.cn/problems/3498/learning/?subject_code=1&group_code=4&match_num=14&match_flow=1&origin=cup
#include <iostream>
#include<cmath>
using namespace std;
int main()
{double n=23333333;double sum=0;for(int x=0;x<=n/2;x++){sum=0;sum-=x*(x/n)*log2(x/n)+(n-x)*(n-x)/n*log2((n-x)/n);if(sum>11625907.5&&sum<11625907.6){cout<<x;break;}}return 0;
}
填空题难度还行,没有考虑每次循环都要初始化sum为0(出来挨打)(小数记得double一下)
【日期统计】
https://www.lanqiao.cn/problems/3492/learning/?subject_code=1&group_code=4&match_num=14&match_flow=1&origin=cup
#include <iostream>
using namespace std;int main()
{int array[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 count = 0;int monthday[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};//方便一一对照月份for (int month = 1; month <= 12; month++){for (int day = 1; day <= monthday[month]; day++){int k = 0;int date[8] = {2, 0, 2, 3, month / 10, month % 10, day / 10, day % 10};//0几的内种for (int i = 0; i < 100; i++){if (array[i] == date[k])k++;if (k == 8){count++;break;}}}}cout << count;return 0;
}
很久之前写的了,今天又敲了一遍。先循环构造对照数组,再一一比对就o了(少了个日期,朕说怎么过不了,被自己蠢笑啦~(比心)爱笑的小女孩自从学算法之后更爱笑了)
【字串简写】
https://www.lanqiao.cn/problems/3514/learning/?subject_code=1&group_code=4&match_num=14&match_flow=1&origin=cup
#include <iostream>
#include<string>
using namespace std;
int main()
{int k;cin>>k;string s;char c1,c2;cin>>s>>c1>>c2; long long cnt=0,res=0;for(int i=0,j=k-1;j<s.length();i++,j++)//{if(s[i]==c1)cnt++;if(s[j]==c2)res+=cnt;}cout << res;return 0;
}
LL 必须永远被坚定地选择,第一次做有个bug就是不能同时满足等于c1和c2,这样就只会筛选长度为4的串了,所以得先筛一个存着,碰到第二个就加一下
【冶炼金属】
#include <iostream>
#include<algorithm>
using namespace std;
using LL=long long;
int main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);// vo=x;LL n,a,b,x,y,vmin,vmax;cin>>n; for(int i=1;i<=n;i++){cin>>a>>b; x=a/b; y=a/(b+1)+1; vmin=max(vmin,y);vmax=min(vmax,x);}cout<<vmin<<" "<<vmax;return 0;
}
【飞机降落】
感觉难起来了
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define LL long long
LL t[15],d[15],l[15];
LL n;
bool flag;
bool biao[15];
void dfs(LL pos,LL cnt){if(n==pos){flag=true;return;}for(LL i=1;i<=n;++i){if(biao[i]==false&&cnt<=t[i]+d[i]){biao[i]=true;dfs(pos+1,max(cnt,t[i])+l[i]);biao[i]=false;if(flag) return;}}
}
int main(void){LL tt;cin>>tt;while(tt--){cin>>n;for(LL i=1;i<=n;++i){cin>>t[i]>>d[i]>>l[i];}flag=false;for(LL i=1;i<=n;++i){biao[i]=false;}dfs(0,0);if(flag) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
}
【接龙数列】
线性dp
#include <iostream>
using namespace std;
using LL=long long;
const LL N=1e5+3;
int dp[10];
int main()
{int n;cin>>n;int ma=0;string s;for(int i=0;i<n;i++){cin>>s;int x=s[0]-'0';int y=s[s.size()-1]-'0';dp[y]=max(dp[x]+1,dp[y]);ma=max(ma,dp[y]);}cout<<n-ma;// 请在此输入您的代码return 0;
dp[y]=max(dp[x]+1,dp[y])
如果首位和前面存的末位相同的话说明可以形成接龙数列,在末位存储上++;如果不能就重新形成一个接龙数列
以第五个数据为例,以3开头以2结尾,3!=2,如果选择则重新开辟以3为首的存储,如果不选还是保持之前dp[2]的存储状态