明码 |
猴子分香蕉 |
日志统计 |
激光样式 |
最大乘积 |
这个链接好像进不去题目我放下面了抱歉 |
明码:
题目是:
#include<iostream>
#include<algorithm>
#include<stack>
#include<vector>
#include<string>
#include<math.h>
#include<bitset>
using namespace std;
int main(){
int n, m;
while (cin >> n >> m) {
bitset<8> b(n);
string t=b.to_string();
for(int i=0;i<t.size();i++){
if(t[i]=='1'){
cout<<"*";
}
else{
cout<<" ";
}
}
//cout<<b;
bitset<8> c(m);
string s=c.to_string();
for(int i=0;i<s.size();i++){
if(s[i]=='1'){
cout<<"*";
}
if(s[i]=='0'){
cout<<" ";
}
}
cout<<endl;
}
return 0;
}
//这是源代码他要提交的并不是这个,你只需要提交最后的结果
猴子分香蕉
#include<iostream>
#include<algorithm>
#include<stack>
#include<vector>
#include<string>
#include<math.h>
#include<bitset>//进制转换用的
#include<iomanip>//保留小数用的
using namespace std;
int main(){
int x=1,key;
while(1){
key=x;
if(x%5==1){
x=x-(x/5)-1;
if(x%5==2){
x=x-(x/5)-2;
if(x%5==3){
x=x-(x/5)-3;
if(x%5==4){
x=x-(x/5)-4;
if(x%5==0&&x!=0){
break;
}
}
}
}
}
x=key;
x++;
}
cout<<key;
}
日志统计 :
做日志统计这道题获得了很多东西
pair 默认对first升序,当first相同时对second升序;
pair<int,int>a[100];
对pair型数组排序sort(a,a+5,cmp);//对这个数组的前五位排序
cmp是由你自己写的一个函数可以决定它是按照什么来排序的按照first还是second
//sort宝藏函数卧槽当你的first值相等时给你排second的值
#include<iostream>
#include<algorithm>
#include<stack>
#include<vector>
#include<string>
#include<math.h>
#include<bitset>//进制转换用的
#include<iomanip>//保留小数用的
using namespace std;
const int maxn=1e5+5;//10的5次方在加5
pair<int,int>idts[maxn];
int N,D,K;
bool judge(int begin,int end){
int start=begin,end1=begin;
int count=0;
while(start<=end1&&end1<=end)//尺取法
{
count++;
if(count>=K){
if(idts[end1].second-idts[start].second<D){//小于这个时刻
return true;
}
else{
start++;//这在加end1已经没用了
count--;//start+就相当于少了一个点赞了
}
}
end1++;
}
return false;
}
int main(){
cin>>N>>D>>K;
int ts,id;//时刻和id
for(int i=0;i<N;i++){
cin>>ts>>id;
idts[i].first=id;//第一个存放id
idts[i].second=ts;//第二个存放ts时刻
}
sort(idts,idts+N);//默认派列了下first升序排列并且当first相同时自动升序排second
int i=0;
while(i<N){
id=idts[i].first;
int begin=i,end;//begin表示同id下的最小下标end表示
while(id==idts[i].first&&i<N){
end=i;
i++;
}
if(judge(begin,end)){
cout<<idts[begin].first<<endl;
}
}
}
激光样式:
很明显动态规划
a[n]=a[n-1]+a[n-2];(n>=2)
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int a[30];
a[0]=2;a[1]=3;
int i;
for( i=2;i<30;i++){
a[i]=a[i-1]+a[i-2];
}
cout<<a[29]<<endl;
}
最大乘积
next_permutation()函数功能是输出所有比当前排列大的排列,顺序是从小到大。
而prev_permutation()函数功能是输出所有比当前排列小的排列,顺序是从大到小。
next_permutation函数将按字母表顺序生成给定序列的下一个较大的排列,直到整个序列为降序为止。
prev_permutation函数与之相反,是生成给定序列的上一个较小的排列。
//有这
#include <iostream> #include <algorithm> #include<cmath> using namespace std; bool judge(int a,int b){ int s[11]={0}; long long sum; sum=a*b; //cout<<sum; int count=0; while(sum!=0){ int y=sum%10; sum=sum/10; count++; s[y]++; } if(count==9){ for(int i=1;i<=9;i++){ if(s[i]!=1){ return false; } } return true; } return false; }//判断的函数 int main() { long long b=0,c=0,maxn=0; int a[]={1,2,3,4,5,6,7,8,9}; while(next_permutation(a,a+9))//每次都会将数组进行排序的 for(int i=0;i<8;i++){ b=0; c=0; for(int j=0;j<=i;j++){ b=b*10+a[j]; } for(int k=i+1;k<=8;k++){ c=c*10+a[k]; } if(judge(b,c)) { maxn = max(maxn,(b * c)); } } cout<<maxn<<endl; }
个函数这道题就非常好实现了