Problem A
找到最前面和最后面的1,计算中间需要填的坑就可以了。
Problem B
数学题,老数学废物了,看代码吧,不知道咋讲,寄几推一个就可以了。
t=int (input ())
for _ in range (t):
st=list (map (int,input ().split ()))
n=(st[0]+1)//2
x=n//st[1]; y=n%st[1]
if (y==0):
y=st[1]
x-=1
ans=max (st[0],x*(st[1]+st[2])+y)
print (int (ans))
Problem C
是这样的,首先的话,在键盘中一个字母只能出现一次,然后一个字母最多只能有两个adj字母,而且我们password里面必须是有两个只有一个adj元素,这两个条件用来判断是否可以成功构造,接下来就是类似模拟?反正你STL XJB搞就好了。
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
#define rep(i,f_start,f_end) for (int i=f_start;i<=f_end;++i)
#define per(i,n,a) for (int i=n;i>=a;i--)
#define MT(x,i) memset(x,i,sizeof(x) )
#define rev(i,start,end) for (int i=start;i<end;i++)
#define inf 0x3f3f3f3f
#define mp(x,y) make_pair(x,y)
#define lowbit(x) (x&-x)
#define MOD 1000000007
#define exp 1e-8
#define N 1000005
#define fi first
#define se second
#define pb push_back
typedef long long ll;
const ll INF=0x3f3f3f3f3f3f3f3f;
typedef vector <int> VI;
typedef pair<int ,int> PII;
typedef pair<int ,PII> PIII;
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;};
void check_max (int &a,int b) { a=max (a,b);}
void check_min (int &a,int b) { a=min (a,b);}
inline int read() {
char ch=getchar(); int x=0, f=1;
while(ch<'0'||ch>'9') {
if(ch=='-') f=-1;
ch=getchar();
} while('0'<=ch&&ch<='9') {
x=x*10+ch-'0';
ch=getchar();
} return x*f;
}
const int maxn=1e6+10;
string str;
int n;
void solve () {
cin>>str;
map <char,set<char> > mp;
int flag=0;
rev (i,0,str.size ()) {
if (i==0) mp[str[i]].insert (str[i+1]);
else if (i==(str.size ()-1)) mp[str[i]].insert (str[i-1]);
else mp[str[i]].insert (str[i-1]),mp[str[i]].insert (str[i+1]);
}
char st='#',ed='#';
int sign=0;
for (auto it:mp) {
if (it.second.size ()>=3) flag=1;
if (it.second.size ()==1&&sign==0) st=it.first,sign=1;
if (it.second.size ()==1) ed=it.first;
}
string ans="";
if (flag||st=='#'||ed=='#') cout<<"NO"<<endl;
else {
cout<<"YES"<<endl;
set <char> s;
ans+=st;
char temp=st;
s.insert (st);
while (mp[temp].size ()) {
char sit='#';
for (auto it:mp[temp]) {
if (mp[it].size ()>1&&!s.count (it)) {
sit=it;
ans+=it;
s.insert (it);
break;
}
}
temp=sit;
if (sit=='#') break;
}
ans+=ed; s.insert (ed);
for (char i='a';i<='z';i++) if (!s.count (i)) ans+=i;
set <char> k;
rev (i,0,ans.size ()) {
if (k.count (ans[i])) ans.erase (ans.begin ()+i);
else k.insert (ans[i]);
}
cout<<ans<<endl;
}
return ;
}
int main () {
ios::sync_with_stdio (false);
int t;
cin>>t;
while (t--) {
solve ();
}
return 0;
}