CSP-J2022 题解报告
题解报告
乘方:
发现
Code:
// QwQ
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
#define fi first
#define se second
typedef pair<int,int> PII;
typedef long long LL;
template <typename T> void inline read(T& x)
{
x=0; int f=1; char ch;
while((ch=getchar())>'9' || ch<'0') if(ch=='-') f=-1;
while(ch>='0' && ch<='9') x=x*10+(ch^'0'),ch=getchar();
x*=f;
}
int main()
{
int a,b; read(a); read(b);
if(a==1) printf("1\n");
else
{
LL ret=1;
for(int i=1;i<=b;ret*=a,i++)
if(ret>1e9) {puts("-1");return (0-0);}
if(ret>1e9) {puts("-1");return (0-0);}
printf("%lld\n",ret);
}
return (0-0); // QwQ
}
解密:
把第二个式子拆开可以得到
由第一个式子得到
整理
由初中知识可知 NO
。
求出两根后,代入给定式子验证即可。
Code:
// QwQ
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
#define fi first
#define se second
typedef pair<int,int> PII;
typedef long long LL;
template <typename T> void inline read(T& x)
{
x=0; int f=1; char ch;
while((ch=getchar())>'9' || ch<'0') if(ch=='-') f=-1;
while(ch>='0' && ch<='9') x=x*10+(ch^'0'),ch=getchar();
x*=f;
}
void solve()
{
LL n,d,e; read(n); read(d); read(e);
LL p=n-e*d+2;
if(p*p-4*n<0) puts("NO");
else
{
LL x=sqrt(p*p-4*n);
LL s1=(p-x)/2,s2=(p+x)/2;
if(s1*s2!=n) puts("NO");
else if((s1-1)*(s2-1)+1!=e*d) puts("NO");
else printf("%lld %lld\n",s1,s2);
}
}
int main()
{
int T; read(T);
while(T--) solve();
return (0-0); // QwQ
}
逻辑表达式:
做过
Code:
// QwQ
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <stack>
#include <map>
#include <string>
#include <iostream>
using namespace std;
#define fi first
#define se second
typedef pair<int,int> PII;
typedef long long LL;
template <typename T> void inline read(T& x)
{
x=0; int f=1; char ch;
while((ch=getchar())>'9' || ch<'0') if(ch=='-') f=-1;
while(ch>='0' && ch<='9') x=x*10+(ch^'0'),ch=getchar();
x*=f;
}
const int N=1e6+5;
struct tree
{
int l,r,op,v;
}e[N];
string opt;
int n,cnt,ret[2];
map <char,int> mp={{'|',1},{'&',2}};
stack <int> num;
stack <char> op;
void get()
{
int r=num.top(); num.pop();
int l=num.top(); num.pop();
char c=op.top(); op.pop();
++cnt;
e[cnt].op=(c=='|'?1:0);
e[cnt].l=l,e[cnt].r=r;
if(c=='|') e[cnt].v=e[l].v|e[r].v;
else e[cnt].v=e[l].v&e[r].v;
num.push(cnt);
//printf("kk%d %d %c\n",a,b,c);
//printf("%d %d\n",cnt[0],cnt[1]);
}
void dfs(int x)
{
//printf("%d %d %d %d %d %d\n",x,e[x].op,e[x].l,e[e[x].l].v,e[x].r,e[x].v);
if(e[x].op==0)
{
if(!e[e[x].l].v) ret[0]++,dfs(e[x].l);
else dfs(e[x].l),dfs(e[x].r);
}
else if(e[x].op==1)
{
if(e[x].op && e[e[x].l].v) ret[1]++,dfs(e[x].l);
else dfs(e[x].l),dfs(e[x].r);
}
}
int main()
{
ios::sync_with_stdio(0);
cin>>opt; opt='('+opt+')'; n=opt.length();
for(int i=0;i<n;i++)
{
if(opt[i]=='(') op.push(opt[i]);
else if(opt[i]=='&')
{
while(!op.empty() && op.top()=='&') get();
op.push(opt[i]);
}
else if(opt[i]=='|')
{
while(!op.empty() && op.top()!='(') get();
op.push(opt[i]);
}
else if(opt[i]==')')
{
while(!op.empty() && op.top()!='(') get();
op.pop();
}
else
{
++cnt;
e[cnt].v=opt[i]-'0';
e[cnt].op=-1;
num.push(cnt);
//printf("%d %d\n",cnt[0],cnt[1]);
}
}
cout<<e[num.top()].v<<"\n";
dfs(num.top());
cout<<ret[0]<<" "<<ret[1]<<"\n";
return (0-0); // QwQ
}
T4 上升点列:
此题可以
方程:
首先要把所有点排序,第一维枚举走到哪个点
时间复杂度:
Code:
// QwQ
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
#define fi first
#define se second
typedef pair<int,int> PII;
typedef long long LL;
template <typename T> void inline read(T& x)
{
x=0; int f=1; char ch;
while((ch=getchar())>'9' || ch<'0') if(ch=='-') f=-1;
while(ch>='0' && ch<='9') x=x*10+(ch^'0'),ch=getchar();
x*=f;
}
const int N=505;
PII a[N];
int n,k,dp[N][N];
int get(int x,int y)
{
if(a[x].fi-a[y].fi<0) return -1;
if(a[x].se-a[y].se<0) return -1;
return a[x].fi-a[y].fi+a[x].se-a[y].se;
}
int main()
{
read(n); read(k);
for(int i=1;i<=n;i++) read(a[i].fi),read(a[i].se);
sort(a+1,a+1+n);
//puts("caonima");
//for(int i=1;i<=n;i++) printf("%d %d\n",a[i].fi,a[i].se);
for(int i=1;i<=n;i++) dp[i][0]=1;
for(int i=1;i<=n;i++)
for(int j=1;j<i;j++)
for(int l=0;l<=k;l++)
if(get(i,j)==1)
dp[i][l]=max(dp[i][l],dp[j][l]+1);
else if(get(i,j)!=-1 && get(i,j)-1<=l)
dp[i][l]=max(dp[i][l],dp[j][l-get(i,j)+1]+get(i,j));
/*
for(int i=1;i<=n;i++)
for(int j=0;j<=k;j++)
printf("%d%c",dp[i][j]," \n"[j==k]);
*/
int ret=0;
for(int i=1;i<=n;i++)
for(int j=0;j<=k;j++)
ret=max(ret,dp[i][j]+k-j);
printf("%d\n",ret);
return (0-0); // QwQ
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!