A、
a题模拟一下
#include<iostream>
#include<algorithm>
#include<cstring>
#include <cmath>
#include<vector>
using namespace std;
int main()
{
int n;
scanf ("%d",&n);
int a = n/100;
int b = (n-a*100)/10;
int c = n%10;
cout<<n+b*100+c*10+a+c*100+a*10+b<<endl;
return 0;
}
B、
题意:给你1e5个数,让你从第一个数开始如果下一个数大于第一个数就可以跑到下一个数,问你能跑到的最大数。
#include<iostream>
#include<algorithm>
#include<cstring>
#include <cmath>
#include<vector>
using namespace std;
int main()
{
int n;
scanf ("%d",&n);
int res;
for (int i=0;i<n;i++)
{
int x;
scanf ("%d",&x);
if (i==0)
res = x;
else if (x>res)
{
res = x;
}
else
break;
}
cout<<res<<endl;
return 0;
}
C、
题意:我们有一个N个数的序列,然后给你2e5次询问,每次询问让你求数x第k次出现的下标,没有输出-1.
思路:读题时发现逻辑就有双层映射,嵌套哈希表!!!
#include<iostream>
#include<algorithm>
#include<cstring>
#include <cmath>
#include<vector>
#include<map>
using namespace std;
typedef pair<int,int> PII;
int main()
{
int n,q;
scanf ("%d%d",&n,&q);
map<int,map<int,int> > mh;
for (int i=1;i<=n;i++)
{
int x;
scanf ("%d",&x);
if (!mh.count(x))
{
mh[x][1] = i;
}
else
{
int t = mh[x].size();
mh[x][t+1] = i;
}
}
while (q--)
{
int x,k;
scanf ("%d%d",&x,&k);
if (mh[x][k])
{
printf ("%d\n",mh[x][k]);
}
else
printf ("-1\n");
}
return 0;
}
D、
题意:给定a,n.黑板上刚开始写着1,记为x,每次操作可以得到x*a,如果x是两位以上并且不被10整除,将x的最低位提到最高位变为xx.问最少经过多少次操作使1变为n。
思路:题目叙述就充满着bfs的味道^--------->.
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include <cmath>
#include<queue>
#include<map>
#include<set>
#define x first
#define y second
using namespace std;
typedef pair<int,int> PII;
int main()
{
int a,n;
scanf ("%d%d",&a,&n);
queue<PII> mh;
set<int> ml;
mh.push({1,0});
while (mh.size())
{
PII t = mh.front();
mh.pop();
if (!ml.count(t.x*a)&&t.x*a<1000000)
{
if (t.x*a==n)
{
cout<<t.y+1<<endl;
return 0;
}
mh.push({t.x*a,t.y+1});
ml.insert(t.x*a);
}
if (t.x%10!=0&&t.x>10)
{
string s = to_string(t.x);
// cout<<s<<' ';
int k = s.size();
char l = s[k-1];
s = l+s;
int f=0;
for (int i=0;i<s.size()-1;i++)
{
f*=10;
f+=s[i]-'0';
}
// cout<<f<<endl;
if (!ml.count(f))
{
if (f==n)
{
cout<<t.y+1<<endl;
return 0;
}
mh.push({f,t.y+1});
ml.insert(f);
}
}
}
cout<<-1<<endl;
return 0;
}
第一次排名这么靠前,截图留念