2.2
A - Free Ice Cream
https://codeforces.com/contest/686/problem/A
题解
水题
Code
#include<bits/stdc++.h>
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int inf=0x3f3f3f3f;
typedef long long ll;
const int N= 1e5+7;
const ll mod=998244353;
int main(){
IO;
int t=1;
//cin>>t;
while(t--){
ll n,x;
cin>>n>>x;
int cnt=0;
while(n--){
char y;
int z;
cin>>y>>z;
if(y=='+')x+=z;
else{
if(x>=z)x-=z;
else cnt++;
}
}cout<<x<<" "<<cnt<<endl;
}
return 0;
}
B - Little Robber Girl's Zoo
https://codeforces.com/contest/686/problem/B
题解
题意为选择一个偶数的区间其中两两交换位置,保证选择数量在20000次内完成数组的排序,我们可以考虑使用冒泡排序的思路,复杂度为n*n,可以过。
Code
#include<bits/stdc++.h>
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int inf=0x3f3f3f3f;
typedef long long ll;
const int N= 1e5+7;
const ll mod=998244353;
ll a[107],b[107];
int main(){
IO;
int t=1;
//cin>>t;
while(t--){
int n;
cin>>n;
for (int i = 1; i <= n; ++i)
{
cin>>a[i];
b[i]=a[i];
}vector<int>l,r;
sort(b+1,b+n+1);
for (int i = 1; i <= n; ++i)
{
if(b[i]!=a[i])
{
int j=i+1;
while(a[j]!=b[i])j++;
while(j>i){
r.push_back(j);
l.push_back(j-1);
swap(a[j],a[j-1]);
j--;
}
}
}
for (int i = 0; i < l.size(); ++i)
{
cout<<l[i]<<" "<<r[i]<<endl;
}
}
return 0;
}
C - Robbers' watch
https://codeforces.com/contest/686/problem/C
题解
题意为给出两个数(n,m),求出(a,b)的数量(0=<a<n,0=<b<m,并且a,b的7进制数不能有重复数字,并且位数分别与n-1、m-1相同)。
因为a和b的位数最多是7,当超过7时比出现重复数字。
直接枚举0-6的全排列并且判断即可。
注意判断a和b的位数时需要求n-1和m-1的位数而不是n和m的位数(7进制下)。
Code
#include<bits/stdc++.h>
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int inf=0x3f3f3f3f;
typedef long long ll;
const int N= 1e5+7;
const ll mod=998244353;
int a[10];
int main(){
IO;
int t=1;
//cin>>t;
while(t--){
map<ll,int>mp1,mp2;
ll n,m;
cin>>n>>m;
n--;m--;
ll k1=0,k2=0;
ll x=n,y=m;
if(!x)k1++;
if(!y)k2++;
while(x){
x/=7;
k1++;
}while(y){
y/=7;
k2++;
}ll k=k1+k2;
if(k>7){
cout<<0<<endl;continue;
}
for (int i = 0; i < 7; ++i)
{
a[i]=i;
}ll cnt=0;
int p=1;
do{
ll base=7;
ll sum1=0;int i;
for ( i = 0; i < k1; ++i)
{
sum1*=base;
sum1+=a[i];
}if(sum1>n)continue;
ll sum2=0;int j=0;
for ( i = k1; j < k2; ++i,++j)
{
sum2*=base;
sum2+=a[i];
}
if(sum2>m)continue;
if((!mp1[sum1]||!mp2[sum2])||(mp1[sum1]&&mp2[sum2]&&mp1[sum1]!=mp2[sum2]))cnt++;
mp1[sum1]=p;
mp2[sum2]=p;
p++;
}while(next_permutation(a,a+7));cout<<cnt <<endl;
}
return 0;
}
Code will change the world !
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 一文彻底搞懂 MCP:AI 大模型的标准化工具箱
· 电商平台中订单未支付过期如何实现自动关单?
· 用 .NET NativeAOT 构建完全 distroless 的静态链接应用
· 为什么构造函数需要尽可能的简单
· 探秘 MySQL 索引底层原理,解锁数据库优化的关键密码(下)
· 短信接口被刷爆:我用Nginx临时止血
· .NET 平台上的开源模型训练与推理进展
· Google发布A2A开源协议:“MCP+A2A”成未来标配?
· C# 多项目打包时如何将项目引用转为包依赖
· 一款让 Everything 更加如虎添翼的 .NET 开源辅助工具!