\(CSP-J2022\) 题解报告

\(T1\) 乘方:

发现 \(2^{32}>10^9\),所以这个题只需要特判 \(a=1\) 的情况为 \(1\),其他直接枚举再判断即可。

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
}

\(T2\) 解密:

把第二个式子拆开可以得到 \(e\times d=p\times q-p-q+2\)

由第一个式子得到 \(p=n/q\),然后代进去 \(e\times d=n-\frac{n}{q}-q+2\)

整理 \(-q^2-(n-e\times d+2)q-n=0\)。

由初中知识可知 \(\Delta =(n-e\times d+2)^2-4n<0\) 则无实根,输出 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
}

\(T3\) 逻辑表达式:

做过 \(CSP-J2020 T3\) 的应该都看得出来,这两个题本质差不多,都是建表达式树,当一个短路操作发生,只需要舍去他的右儿子即可,不难实现。

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 上升点列:

此题可以 \(dp\),设状态 \(dp_{i,l}\) 表示到了第 \(i\) 个点,新加了 \(l\) 个点的最多点数。

方程:\(dp_{i,l}=max(dp_{i,l},dp_{j,l-dis(i,j)+1}+dis(i,j))\)

首先要把所有点排序,第一维枚举走到哪个点 \(i\),第二维枚举由哪个点 \(j\) 走到当前点 \(i\),第三维枚举新加的点数 \(l\)。

时间复杂度:\(O(n^2k)\),空间复杂度:\(O(nk)\)。足以通过本题。

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
}

尾:欢迎大家来吊打。

CSP-J2022 题解报告的更多相关文章

  1. 2015浙江财经大学ACM有奖周赛(一) 题解报告

    2015浙江财经大学ACM有奖周赛(一) 题解报告 命题:丽丽&&黑鸡 这是命题者原话. 题目涉及的知识面比较广泛,有深度优先搜索.广度优先搜索.数学题.几何题.贪心算法.枚举.二进制 ...

  2. cojs 强连通图计数1-2 题解报告

    OwO 题目含义都是一样的,只是数据范围扩大了 对于n<=7的问题,我们直接暴力搜索就可以了 对于n<=1000的问题,我们不难联想到<主旋律>这一道题 没错,只需要把方程改一 ...

  3. cojs 二分图计数问题1-3 题解报告

    OwO 良心的FFT练手题,包含了所有的多项式基本运算呢 其中一部分解法参考了myy的uoj的blog 二分图计数 1: 实际是求所有图的二分图染色方案和 我们不妨枚举这个图中有多少个黑点 在n个点中 ...

  4. 题解报告:hdu 1398 Square Coins(母函数或dp)

    Problem Description People in Silverland use square coins. Not only they have square shapes but also ...

  5. 题解报告:hdu 2069 Coin Change(暴力orDP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2069 Problem Description Suppose there are 5 types of ...

  6. 题解报告:hdu 1028 Ignatius and the Princess III(母函数or计数DP)

    Problem Description "Well, it seems the first problem is too easy. I will let you know how fool ...

  7. CF Educational Round 78 (Div2)题解报告A~E

    CF Educational Round 78 (Div2)题解报告A~E A:Two Rival Students​ 依题意模拟即可 #include<bits/stdc++.h> us ...

  8. CF1169(div2)题解报告

    CF1169(div2)题解报告 A 不管 B 首先可以证明,如果存在解 其中必定有一个数的出现次数大于等于\(\frac{m}{2}\) 暴力枚举所有出现次数大于等于$\frac{m}{2} $的数 ...

  9. CFEducational Codeforces Round 66题解报告

    CFEducational Codeforces Round 66题解报告 感觉丧失了唯一一次能在CF上超过wqy的机会QAQ A 不管 B 不能直接累计乘法打\(tag\),要直接跳 C 考虑二分第 ...

  10. CF Round #580(div2)题解报告

    CF Round #580(div2)题解报告 T1 T2 水题,不管 T3 构造题,证明大约感性理解一下 我们想既然存在解 \(|a[n + i] - a[i]| = 1\) 这是必须要满足的 既然 ...

随机推荐

  1. 在Yarn集群上跑spark wordcount任务

    准备的测试数据文件hello.txt hello scala hello world nihao hello i am scala this is spark demo gan jiu wan le ...

  2. 学习ASP.NET Core Blazor编程系列二——第一个Blazor应用程序(下)

    学习ASP.NET Core Blazor编程系列一--综述 学习ASP.NET Core Blazor编程系列二--第一个Blazor应用程序(上) 学习ASP.NET Core Blazor编程系 ...

  3. 重复造轮子 SimpleMapper

    接手的项目还在用 TinyMapper 的一个早期版本用来做自动映射工具,TinyMapper 虽然速度快,但在配置里不能转换类型,比如 deleted 在数据库中用 0.1 表示,转换成实体模型时没 ...

  4. [Python]-torchvision.transforms模块-图像预处理

    PyTorch框架中常用torchvision模块来辅助计算机视觉算法的搭建,transforms用于图像的预处理. from torchvision import transforms 预处理操作集 ...

  5. 微信小程序-全局配置、组件、页面跳转、用户信息等

    全局配置 三个页面 app.json pages字段 "pages":[ "pages/index/index", # 首页 "pages/home/ ...

  6. Java语言(基础一)

    Java语言 Java的特性和优势 简单性(简单易学) 面向对象(一种思想 万物皆对象) 可移植性(一次编写到处运行 JVM) 高性能(及时编译) 分布式(网络分布式url) 动态性(反射机制) 多线 ...

  7. 第四章:Django表单 - 5:模型表单ModelForm

    如果你正在构建一个数据库驱动的应用,那么你可能会有与Django的模型紧密映射的表单.比如,你有个BlogComment模型,并且你还想创建一个表单让大家提交评论到这个模型中.在这种情况下,写一个fo ...

  8. 使用metricbeat监控system和nginx

    下载并解压缩metricbeat metricbeat.yml配置文件设置: setup.kibana: host: "192.168.75.21:5601" output.ela ...

  9. Prometheus 监控报警系统 AlertManager 之邮件告警

    转载自:https://cloud.tencent.com/developer/article/1486483 文章目录1.Prometheus & AlertManager 介绍2.环境.软 ...

  10. Apollo 中配置String、Map和List和默认值

    摘要:在Apollo 中,配置String.Map和List等类型的信息,同时设置默认值. 综述   随着业务需求的变更,需要在Apollo中配置一个Map<String, List>类型 ...