int n, k, p;
voidsolve(){
cin >> n >> k >> p;
if((k>0 && n*p < k )|| (k<0 && -n*p > k)){
cout << -1 << endl;
}else{
if(k<0){
k = -k;
}
cout << k/p+(k%p ? 1: 0) << endl;
}
}
2. Having Been a Treasurer in the Past, I Help Goblins Deceive
#define int long longint n;
voidsolve(){
cin >> n;
string s; cin >> s;
int cntl = 0, cntr = 0;
for(int i=0; i<n; i++){
if(s[i] == '-') cntl++;
else cntr++;
}
int l = cntl/2;
int r = cntl-l;
int ans = l*r*cntr;
cout << ans << endl;
}
3. Creating Keys for StORages Has Become My Main Skill
#define int long longvoidsolve(){
int n, x; cin >> n >> x;
int cx = x;
int a[n], cnt = 0;
memset(a, 0, sizeof(a));
vector<int> q;
int p = 0, cnt1 = 0;
while(x){
if((x&1) == 0){
q.push_back(p);
}else{
cnt1++;
}
x >>= 1;
p++;
}
// 符合就放,不符合就跳过,直到所有的位都访问过了bool vis[p];
memset(vis, 0, sizeof(vis));
int len = q.size();
for(int i=0; i<n; i++){
for(int k=0; k<len; k++){
if((i >> q[k]) == 1) goto lable;
}
a[cnt++] = i;
if(i>=((1<<(p))-1)) break;
}
lable: ;
int t = 0;
for(int i=0; i<n; i++){
t |= a[i];
}
if(t != cx){
a[n-1] = cx;
}
int tt = 0;
for(int i=0; i<n; i++){
cout << a[i] << ' ';
tt |= a[i];
}
cout << endl;
// cout << tt << endl;
}
4. For Wizards, the Exam Is Easy, but I Couldn't Handle It
#define int long longvoidsolve(){
int n; cin >> n;
int a[n];
for(int i=0; i<n; i++) cin >> a[i];
int ans = 0, ansl = 0, ansr = 0;
for(int i=0; i<n; i++){
int cnt = 0;
for(int k=i+1; k<n; k++){
if(a[i] > a[k]) cnt++;
if(a[i] < a[k]) cnt--;
if(ans < cnt){
ans = cnt;
ansl = i, ansr = k;
}
}
}
cout << ansl+1 << ' ' << ansr+1 << endl;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架