当前位置: 首页 > news >正文

2022 CSP-J复赛题

乘方

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{ll a,b;cin>>a>>b;if(a==1){cout<<1<<endl;return 0;}ll res=1;for(int i=0;i<b;i++){res *=a;if(res>1e9){cout<<-1<<endl;return 0;}}cout<<res<<endl;return 0;
}

解密

#include <bits/stdc++.h>
using namespace std;typedef long long ll;int main() {ios::sync_with_stdio(false);cin.tie(0);int k;cin >> k;while (k--) {ll n, e, d;cin >> n >> e >> d;ll m = n - e * d + 2;  ll delta = m * m - 4 * n;if (delta < 0) { cout << "NO\n";continue;}ll sqrt_delta = sqrt(delta); if (sqrt_delta * sqrt_delta != delta) {cout << "NO\n";continue;}if ((m - sqrt_delta) % 2 != 0) { cout << "NO\n";continue;}ll p = (m - sqrt_delta) / 2;ll q = (m + sqrt_delta) / 2;if (p * q == n && p <= q) {  cout << p << " " << q << "\n";} else {cout << "NO\n";}}return 0;
}

逻辑表达式

#include <bits/stdc++.h>
using namespace std;string s;
int idx;  
int ans1, ans2;  bool calc() {bool res = false;      bool has_val = false;  int i = idx;while (idx < s.size() && s[idx] != ')') {if (s[idx] == '(') {idx++;  // 跳过'('bool val = calc(); idx++;  // 跳过')'if (!has_val) {res = val;has_val = true;} else if (res == 1 && s[i] == '|') {ans2++;int cnt = 0;while (idx < s.size()) {if (s[idx] == '(') cnt++;else if (s[idx] == ')') {if (cnt == 0) break;cnt--;} else if (cnt == 0 && s[idx] == '|') {ans2++;                    } else if (cnt == 0 && s[idx] == '&') {break; }idx++;}} else if (res == 0 && s[i] == '&') {ans1++;int cnt = 0;while (idx < s.size()) {if (s[idx] == '(') cnt++;else if (s[idx] == ')') {if (cnt == 0) break;cnt--;} else if (cnt == 0 && s[idx] == '&') {ans1++; } else if (cnt == 0 && s[idx] == '|') {break; }idx++;}} else {// 正常计算if (s[i] == '&') res &= val;else res |= val;}i = idx; } else if (s[idx] == '0' || s[idx] == '1') {bool val = (s[idx] == '1');idx++;if (!has_val) {res = val;has_val = true;} else if (res == 1 && s[i] == '|') {ans2++;int cnt = 0;while (idx < s.size()) {if (s[idx] == '(') cnt++;else if (s[idx] == ')') {if (cnt == 0) break;cnt--;} else if (cnt == 0 && s[idx] == '|') {ans2++; } else if (cnt == 0 && s[idx] == '&') {break; }idx++;}} else if (res == 0 && s[i] == '&') {ans1++;int cnt = 0;while (idx < s.size()) {if (s[idx] == '(') cnt++;else if (s[idx] == ')') {if (cnt == 0) break;cnt--;} else if (cnt == 0 && s[idx] == '&') {ans1++; } else if (cnt == 0 && s[idx] == '|') {break;}idx++;}} else {if (s[i] == '&') res &= val;else res |= val;}i = idx;} else {idx++;}}return res;
}int main() {cin >> s;idx = 0;ans1 = ans2 = 0;bool result = calc();cout << (result ? "1" : "0") << endl;cout << ans1 << " " << ans2 << endl;return 0;
}

http://www.dtcms.com/a/474930.html

相关文章:

  • 【cubeide】IIC通信
  • python学习之访问模式和文件定位操作
  • CTF攻防世界WEB精选基础入门:simple_php
  • CodexField 热度登顶:内容资产化赛道的加速信号
  • 00_k8s容器编排系统
  • 广西柳州网站制作公司厦门做网站排名
  • 算法学习 02
  • 广西建设监理协会官网站珠海响应式网站建设推广公司
  • 机器学习实践项目(一)- Rossman商店销售预测 - 特征工程
  • 网站首页轮播图片wordpress不支持中文
  • Blender经典像素风模拟插件 Drips Psx Efx – Playstation 1 Effects V1.4
  • 网站 备案 固话福州网站设计软件公司
  • 达梦数据库版本升级方案
  • 【开题答辩全过程】以 北上广咖啡门店分布与销售数据分析和可视化为例,包含答辩的问题和答案
  • 企业信息门户网站 建设基于多站点的网站内容管理平台的管理与应用
  • 基于Vue的高校学习讲座预约系统
  • 钦州网站建设哪家便宜莆田企业自助建站系统
  • 怎样做自己的视频网站建设网站工作室的问题疑问
  • 网站 图片水印wordpress文章数据库
  • KMSEnvelope Encryption
  • 成都住房和城乡建设厅网站鼠标垫东莞网站建设
  • 身份证批量ocr
  • ansible role配apt源
  • SNH48 抢购助手:从软件授权到自动化交易
  • 怎么把网站排名排上去软件开发费用明细
  • 写作网站招聘大连建设局网站地址
  • Java、C语言、Python、PHP、C#、C++编程语言的选择指南
  • 网站管理建设的总结国内永久免费crm代码
  • fastadmin 关闭日志 /runtime/log 这里的日志 关闭
  • 多模态项目:Python人脸表情系统 CNN算法 神经网络+Adaboost定位+PyQt5界面 源码+文档 深度学习实战✅