Problem - A - Codeforces

题目大意:给你一个数组,只由两个数字组成,其中一个数字只出现了一次,求该数字出现的下标位置.

思路:直接模拟

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
#define rep(x,y,z) for(int x=y; x<=z; ++x)
#define dec(x,y,z) for(int x=y; x>=z; --x)
int t, n;
set<int>s;
int a[105];
int main(){cin>>t;int cur;while(t--){s.clear();cin>>n;rep(i,1,n){cin>>a[i];if(s.count(a[i]))cur = a[i];else s.insert(a[i]);}rep(i,1,n){if (a[i] != cur){cout << i << endl;}}}return 0;
}

Problem - B - Codeforces

题目大意:在一张地图上给定两个"*",添加两个’’*“来使得所有的”*"凑成最小的矩形.

思路:直接模拟,如果两个"*"的不在一条直线上,那么另外两点只需要组合一下当前点的x,y.如果两点处在同一直线上,那么直接枚举一下移动一步的情况.

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
#define rep(x,y,z) for(int x=y; x<=z; ++x)
#define dec(x,y,z) for(int x=y; x>=z; --x)
char m[405][405];
int t, n;
int x[2], y[2];
int main(){cin>>t;while(t--){cin>>n;rep(i,1,n){rep(j,1,n){cin>>m[i][j];}}int index= 0;rep(i,1,n){rep(j,1,n){if (m[i][j] == '*'){x[index] = i;y[index] = j;index++;}}}int dx = abs(x[0]-x[1]), dy = abs(y[0]-y[1]);if (dy == 0){  //在同一列if (y[0] > 1)m[x[0]][y[0]-1] = '*', m[x[1]][y[1]-1] = '*';else m[x[0]][y[0]+1] = '*', m[x[1]][y[1]+1] = '*';}else if (dx == 0){    //在同一行if (x[0] > 1)m[x[0]-1][y[0]] = '*', m[x[1]-1][y[1]] = '*';else m[x[0]+1][y[0]] = '*', m[x[1]+1][y[1]] = '*';}else{m[x[0]][y[1]] = '*';m[x[1]][y[0]] = '*';}rep(i,1,n){rep(j,1,n){cout << m[i][j];}cout << endl;}}return 0;
}

Problem - C - Codeforces

题目大意:给定一个字符串,由0,1,?组成,你可以将?替换成0或1,每个?的替换是独立的,求经过一系列替换之后,是否可以使得该串成为由a个0和b个1组成的回文串.

思路:可以划分为这么几个步骤

  1. 将已有的串上对应的?进行补全.
  2. 检查当前恢复过后的串是否为回文串.
  3. 填充剩余部分的?,每次同时填充2个0
  4. 当串长度为奇数时,进行特判,检查处理过后的串0和1的个数是否为a和b.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
#define rep(x,y,z) for(int x=y; x<=z; ++x)
#define dec(x,y,z) for(int x=y; x>=z; --x)
int t, a, b, n;
string s;bool replay() {    //补全rep(i, 0, n-1) {if (s[i] == '?'&&s[n-i-1] == '1')s[i] = '1';else if (s[i] == '?' && s[n-i-1] == '0')s[i] = '0';}rep(i, 0, n-1) {if (s[i] != s[n - i - 1])return false;}return true;
}void solve() {cin >> a >> b >> s;n = a+b;if (!replay()) {cout << -1 << endl;return;}if (a % 2 && b % 2) {cout << -1 << endl;return;}rep(i, 0, n - 1) { //统计已有个数if (s[i] == '1')b--;else if (s[i] == '0')a--;}if (a < 0 || b < 0){cout<< -1 << endl;return;}rep(i, 0, (n / 2) - 1) {if (s[i] == '?') {if (a >= 2) {   //满足条件才能进行替换a -= 2;s[i] = s[n - i - 1] = '0';}else if(b>=2){b -= 2;s[i] = s[n - i - 1] = '1';}}}if (n&1){ //特判if (s[n/2] == '?'){if (a>0){s[n/2] = '0';a--;}else{s[n/2] = '1';b--;}}}if (a == 0 && b == 0)cout << s << endl;else cout << -1 << endl;
}int main() {cin >> t;while (t--) {solve();}return 0;
}

Problem - D - Codeforces

题目大意:给定长度为n+2的序列,请你从序列中选定一个数x一个数sum,余下的数构成一个长度为n的数列,使得该数列中所有项的和等于sum.

思路:思维题,首先我们要考虑的是要使得n个数和等于另一个数,那么为了保证有等于的可能,那么最大的那个数只能作为被抛弃掉的,或者是作为和来进行处理,除此之外该数会被作为构造序列中的元素,而此时没有更大的数,此时没有任何一个数大于该序列和.所以只考虑两种情况

  1. 最大数作和:前n+1个数中的n个数的和等于第n+2个数.
  2. 前n个数的和等于第n+1个数.

清楚了这一点之后代码实现起来就很简单了.

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
#define rep(x,y,z) for(int x=y; x<=z; ++x)
#define dec(x,y,z) for(int x=y; x>=z; --x)
int t, n;
const int MAX = 2e5 + 5;
ll b[MAX], pre[MAX];int main() {cin >> t;while (t--) {cin >> n;rep(i, 1, n + 2)cin >> b[i];sort(b + 1, b + 3 + n);int index1 = 0, index2 = n + 2;rep(i, 1, n + 1)pre[i] = pre[i - 1] + b[i];ll cur = pre[n + 1] - b[n + 2];bool flag = true;if (cur > 0)rep(i, 1, n + 1) {if (b[i] == cur) {index1 = i;break;}}if (index1 == 0) {if (pre[n] == b[n + 1]) {index1 = n + 1;}else {flag = false;}}if (flag){rep(i,1,n+2){if (i == index1 || i == index2)continue;cout << b[i] << " ";}cout << endl;}else cout << -1 << endl;}return 0;
}

Problem - E - Codeforces

题目大意:给定四个数n, l, r, s,你可以对一个由1到n的序列进行排列,使得pl+pl+1+pl+2+…pr = s.

思路:首先需要确定的是,序列和最大的两种取法

  1. n , n-1, n-2, …
  2. 1, 2, 3, …

如果s的大小不在上述两种情况的区间内,那么一定是不合法的.

因为排列可以选择任意的方式,只需要序列中的每个数更不相等即可,那么可以采取n, n-1, n-2…的方式在取序列,然后再依次从后向前减小每一项的值,对于最后一项最小减小值为1,然后下一项为2,不断往前递推,求出序列后,只需要重新输出答案即可.

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
#define rep(x,y,z) for(int x=y; x<=z; ++x)
#define dec(x,y,z) for(int x=y; x>=z; --x)
int t, n;
int a[505];
int b[505];
int l, r, num;
set<int>s;void solve(){s.clear();cin>>n>>l>>r>>num;int len = r - l +1;if ((1+len)*len/2 > num){cout <<-1<<endl;return;}if ((n+n-len+1)*len/2 < num){cout <<-1<<endl;return;}rep(i,1,len){b[i] = n-i+1;}int sum = (n+n-len+1)*len/2;dec(i,len,1){if(sum > num){int temp = b[i] - (len-i+1);if (temp > sum-num){temp = sum-num;}sum-=temp;b[i] -= temp;}if(sum == num)break;}rep(i,1,len)s.insert(b[i]);int ans = 1, index = 1;while(index < l){if (!s.count(ans)){cout << ans << " ";s.insert(ans);index++;}ans++;}rep(i, 1, len)cout << b[i] << " ";rep(i,1,n){if (!s.count(i)){cout << i << " ";s.insert(i);}}cout << endl;
}
int main(){cin>>t;while(t--){solve();}return 0;
}

Codeforces Round #713 (Div. 3)题解相关推荐

  1. Codeforces Round #514 (Div. 2)题解

    Codeforces Round #514 (Div. 2)题解 A 喵,直接模拟. B 枚举所有盖章时的,合法的,左上角的位置.能盖的话就盖一下.最后check一下图案是否相等即可 C 一轮一轮的扔 ...

  2. Codeforces Round #182 (Div. 1)题解【ABCD】

    Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...

  3. 【算法题解】Codeforces Round #817 (Div. 4)题解

    文章目录 Codeforces Round #817 (Div. 4)题解 A. Spell Check B. Colourblindness C. Word Game D. Line E. Coun ...

  4. Codeforces Round #747 (Div. 2)题解

    Codeforces Round #747 (Div. 2)题解 (本博客将持续更新以后每场CF div2的题解,喜欢ACM.OI的小伙伴记得点个关注哟) 昨天夜晚刷网络流刷入迷了,渐渐就忘记了我还要 ...

  5. Codeforces Round #789 (Div. 2)题解

    Codeforces Round #789 (Div. 2)题解 A. Tokitsukaze and All Zero Sequence 原题链接 算法标签 贪心 排序 思路 情况一:数组存在零 → ...

  6. Codeforces Round #748 (Div. 3) 题解 完整A~G

    Codeforces Round #748 (Div. 3) 题解 A. Elections 题意 已知竞选中三个候选人的当前得票数 a , b , c a,b,c a,b,c,现在可以增加任何一个人 ...

  7. Codeforces Round #533 (Div. 2)题解

    link orz olinr AK Codeforces Round #533 (Div. 2) 中文水平和英文水平都太渣..翻译不准确见谅 T1.给定n<=1000个整数,你需要钦定一个值t, ...

  8. Codeforces Round #734 (Div. 3) 题解

    Hello大家好,今天给大家带来的是 Codeforces Round #734 (Div. 3) 的全题目讲解. 本文链接:https://www.lanqiao.cn/questions/2040 ...

  9. Codeforces Round #462 (Div. 2)题解

    Codeforces Round #462 (Div. 2) B题--我固执的认为1e18是18位数,导致被hack,花了20分钟才检查出这个错误,很僵硬 Codeforces 934C 题意 给定一 ...

最新文章

  1. python3socket非阻塞_利用Python中SocketServer 实现客户端与服务器间非阻塞通信
  2. 渣硕 面 用友软件 Java开发
  3. java内存模型概述_Java内存模型-快速概述和注意事项
  4. strings命令(Win、Linux均可适用)
  5. Duplicate复制数据库并创建物理StandBy(spfile+不同实例名+不同路径)
  6. CCPC-Wannafly Comet OJ 夏季欢乐赛(2019)E
  7. Oracle存在gap,发现gap及解决
  8. 中兴被逼入绝境,或将出售手机业务?
  9. 【剑指 offer】(二十九)—— 数组中出现次数超过一半的数字(及该数字出现的次数)
  10. C语言笔记(谭浩强)
  11. R | package基础 | Rstudio + devtools 创建/开发R包(初学者 指南| 简明详细流程)
  12. Android 中自定义软键盘
  13. 宝塔利用同一个ip的不同端口号架设多个网站
  14. 使用python实现新浪微博登陆
  15. leach分簇功能实现matlab,LEACH分簇算法实现和能量控制算法实现
  16. SPI Flash是什么?
  17. ionic platform add android环境搭建之难产【i1】【小白-2016.11.5】
  18. linux下查看cpu峰值,linux下查看CPU信息
  19. ​手机微信可以批量删除好友了!(文末送书)
  20. unity音量++_Unity + GDC旅行报告

热门文章

  1. 五轴联动机床的产品分类说明
  2. 取消计算机用户密码页面,电脑怎么关闭开机密码_电脑开机取消登录密码的两种方法-系统城...
  3. 从G_BEGIN_DECLS和 G_END_DECLS说起
  4. ffmpeg 播放器解码
  5. java 核型技术 卷2 pdf_SpringBoot 的 slf4j日志记录
  6. 孩子学编程,作为教育者该如何选择编程语言?
  7. 根据RGB值,JSP页面显示相应颜色色块
  8. Self-Supervised Multi-Channel Hypergraph Convolutional Network for Social Recommendation
  9. 支付宝系列-电脑网站支付
  10. U盘安装ubuntu12.04+win7双系统