Codeforces Round #713 (Div. 3) Editorial

记录一下自己写的前二题本人比较菜

A. Spy Detected!

You are given an array a consisting of n (n≥3) positive integers. It is known that in this array, all the numbers except one are the same (for example, in the array [4,11,4,4] all numbers except one are equal to 4).

Print the index of the element that does not equal others. The numbers in the array are numbered from one.

Input

The first line contains a single integer t (1≤t≤100). Then t test cases follow.

The first line of each test case contains a single integer n (3≤n≤100) — the length of the array a.

The second line of each test case contains n integers a1,a2,…,an (1≤ai≤100).

It is guaranteed that all the numbers except one in the a array are the same.

Output

For each test case, output a single integer — the index of the element that is not equal to others.

样例

4
4
11 13 11 11
5
1 4 4 4 4
10
3 3 3 3 10 3 3 3 3 3
3
20 20 10

输出

2
1
5
3

题意:

就是有t组测试数据,每个测试数据给我们一个长度为n的数组,其中n>=3且数组中的元素值只有2个,而且其中1个元素在数组中只有一个,让我们求该元素的下标。

思路:

这个思路很简单,因为数组长度不超过100,且其中的元素也不超过100,那么我们可以开2个数组,p和s,其中p就是我们存的数组,而s就当哈希表一样存数组值对应的个数,然后我们再枚举一下s其中为1的就是我们要找的元素,然后返回下标就好了。

C++ 代码

#include <algorithm>
#include <cstring>
#include <iostream> using namespace std; const int N = 110;
int t, n;
int s[N];
int p[N];
int main()
{
scanf("%d", &t); while (t--)
{
memset(s, 0, sizeof s); // 每次测试数据的时候都应该把s都置为0
scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
cin >> p[i];
s[p[i]]++; // 将p[i] 所对应的值映射到s中去,并且计数
}
// 这是枚举出来s[]所对应元素为1的就是我们要找的元素,然后返回就好了
for (int i = 1; i <= n; i++)
{
if (s[p[i]] == 1)
{
printf("%d\n", i);
}
}
}
return 0;
}

B. Almost Rectangle

There is a square field of size n×n in which two cells are marked. These cells can be in the same row or column.

You are to mark two more cells so that they are the corners of a rectangle with sides parallel to the coordinate axes.

For example, if n=4 and a rectangular field looks like this (there are asterisks in the marked cells):

. . ∗ .

. . . .

∗ . . .

. . . .

Then you can mark two more cells as follows

∗ . ∗ .

. . . .

∗ . ∗ .

. . . .

If there are several possible solutions, then print any of them.

Input

The first line contains a single integer t (1≤t≤400). Then t test cases follow.

The first row of each test case contains a single integer n (2≤n≤400) — the number of rows and columns in the table.

The following n lines each contain n characters '.' or '*' denoting empty and marked cells, respectively.

It is guaranteed that the sums of n for all test cases do not exceed 400.

It is guaranteed that there are exactly two asterisks on the field. They can be in the same row/column.

It is guaranteed that the solution exists.

Output

For each test case, output n rows of n characters — a field with four asterisks marked corresponding to the statements. If there multiple correct answers, print any of them.

样例

6
4
..*.
....
*...
....
2
*.
.*
2
.*
.*
3
*.*
...
...
5
.....
..*..
.....
.*...
.....
4
....
....
*...
*...

输出

*.*.
....
*.*.
....
**
**
**
**
*.*
*.*
...
.....
.**..
.....
.**..
.....
....
....
**..
**..

题意

有t组测试数据,每个测试数据输入一个数字n表示接下来要输入一个n*n的字符矩阵,且矩阵中有且只有2个*然后我们需要填入2个*让这四个*能够对称,要是有多组的话就输出一组就好了。

思路

本人太菜了,刚看到这题目的时候都没想啥办法,就直接写了,然后写了好多判断不好读。我就说一下我看到的一个比较好的做法把。

我们可以用2个数组存2个*号的坐标。

这个时候我们可以发现有2中情况如下:

第一种:就是2个*号的横纵坐标都不相等,那么这个时候我们只需要将他们交错的坐标位置都用*号代替就好了。

第二种:就是其中的横坐标或者纵坐标相等(不可能横纵坐标都相等,因为必须要有2个*嘛)这个时候用了一个非常巧妙的办法就是,a[0] = a[1] == 0 这个判断让我们减少了所有的边界条件的判断,这是当横坐标相等的时候,如果纵坐标也相等的话我们就将a换成纵坐标的就好了。

接着我们看一下代码吧。

代码

// 题目地址
// https://codeforces.com/contest/1512/problem/B #include <algorithm>
#include <cstring>
#include <iostream> using namespace std; const int N = 410; int t, n;
char g[N][N]; int a[2];
int b[2]; int main()
{
scanf("%d", &t); while (t--)
{
scanf("%d", &n); for (int i = 0; i < n; i++)
scanf("%s", g[i]); int t = 0;
// 找到2个*的下标位置
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
{
if (g[i][j] == '*')
{
a[t] = i;
b[t++] = j;
}
} /*
我们可以知道这个只有三种情况
第一种:*的2个坐标都不等那么我们只需要
直接将他们的交叉坐标点变为*就可以了。
第二种: *的x坐标相等那么我们就可以通过
a[0] = a[1] == 0的方式来处理
如果a[1],等于0的话我们就让a[0]取1,
如果不等的话就让a[0]取0,
因为我们可以输出任意一种就好了。
第三种:同第二种差不多*在y坐标上相等
*/
if (a[0] == a[1])
a[0] = a[1] == 0;
if (b[0] == b[1])
b[0] = b[1] == 0; for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
g[a[i]][b[j]] = '*'; for (int i = 0; i < n; i++)
printf("%s\n", g[i]);
} //system("pause");
return 0;
}

第一次写代码题解,记录下我做过的一些题目,要是大佬们发现有什么错误的地方,还望多多指出错误之处,orz orz orz。

Codeforces Round #713 (Div. 3)AB题的更多相关文章

  1. Codeforces Round #378 (Div. 2) D题(data structure)解题报告

    题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...

  2. Codeforces Round #612 (Div. 2) 前四题题解

    这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...

  3. Codeforces Round #552 (Div. 3) A题

    题目网址:http://codeforces.com/contest/1154/problem/ 题目意思:就是给你四个数,这四个数是a+b,a+c,b+c,a+b+c,次序未知要反求出a,b,c,d ...

  4. Codeforces Round #412 Div. 2 补题 D. Dynamic Problem Scoring

    D. Dynamic Problem Scoring time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  5. Codeforces Round #259 (Div. 2)AB

    链接:http://codeforces.com/contest/454/problem/A A. Little Pony and Crystal Mine time limit per test 1 ...

  6. Codeforces Round #271 (Div. 2) E题 Pillars(线段树维护DP)

    题目地址:http://codeforces.com/contest/474/problem/E 第一次遇到这样的用线段树来维护DP的题目.ASC中也遇到过,当时也非常自然的想到了线段树维护DP,可是 ...

  7. Codeforces Round #425 (Div. 2))——A题&&B题&&D题

    A. Sasha and Sticks 题目链接:http://codeforces.com/contest/832/problem/A 题目意思:n个棍,双方每次取k个,取得多次数的人获胜,Sash ...

  8. Codeforces Round #426 (Div. 2)A题&&B题&&C题

    A. The Useless Toy:http://codeforces.com/contest/834/problem/A 题目意思:给你两个字符,还有一个n,问你旋转n次以后从字符a变成b,是顺时 ...

  9. Codeforces Round #352 (Div. 2),A题与B题题解代码,水过~~

    ->点击<- A. Summer Camp time limit per test 1 second memory limit per test 256 megabytes input s ...

随机推荐

  1. 上万字详解Spark Core(建议收藏)

    先来一个问题,也是面试中常问的: Spark为什么会流行? 原因1:优秀的数据模型和丰富计算抽象 Spark 产生之前,已经有MapReduce这类非常成熟的计算系统存在了,并提供了高层次的API(m ...

  2. P1426 小鱼会有危险吗(JAVA语言)

    题目描述 有一次,小鱼要从A处沿直线往右边游,小鱼第一秒可以游7米,从第二秒开始每秒游的距离只有前一秒的98%.有个极其邪恶的猎人在距离A处右边s米的地方,安装了一个隐蔽的探测器,探测器左右x米之内是 ...

  3. effective解读-第一条 静态工厂创建对象代替构造器

    好处 有名称,能见名知意.例如BigInteger的probablePrime方法 享元模式.单例模式中使用 享元模式:创建对象代价很高,重复调用已有对象,例如数据库连接等.享元模式是单例模式的一个拓 ...

  4. 阳明-K8S训练营全部文档-2020年08月11日14:59:02更新

    阳明-K8S训练营全部文档 Docker 基础 简介 安装 基本操作 Dockerfile Dockerfile最佳实践 Kubernetes 基础 简介 安装 资源清单 Pod 原理 Pod 生命周 ...

  5. 冒泡算法(BubbleSort)

    /*冒泡排序原理 比较相邻的元素.如果前一个元素比后一个元素大,就交换这两个元素的位置. 对每一对相邻元素做同样的工作,从开始第一对元素到结尾的最后一对元素.最终最后位置的元素就是最大值.实现步骤 1 ...

  6. python基础(一):变量和常量

    变量 什么是变量 变量,用于在内存中存放程序数据的容器.计算机的核心功能就是"计算",CPU是负责计算的,而计算需要数据吧?数据就存放在内存里,例如:将梁同学的姓名,年龄存下来,让 ...

  7. 从零玩转SpringSecurity+JWT整合前后端分离

    从零玩转SpringSecurity+JWT整合前后端分离 2021年4月9日 · 预计阅读时间: 50 分钟 一.什么是Jwt? Json web token (JWT), 是为了在网络应用环境间传 ...

  8. (文字版)Qt信号槽源码剖析(三)

    大家好,我是IT文艺男,来自一线大厂的一线程序员 上节视频给大家讲解了Qt信号槽的Qt宏展开推导:今天接着深入分析,进入Qt信号槽源码剖析系列的第三节视频. Qt信号槽宏推导归纳 #define si ...

  9. Vue CLI 是如何实现的 -- 终端命令行工具篇

    Vue CLI 是一个基于 Vue.js 进行快速开发的完整系统,提供了终端命令行工具.零配置脚手架.插件体系.图形化管理界面等.本文暂且只分析项目初始化部分,也就是终端命令行工具的实现. 0. 用法 ...

  10. 在Win10中手动添加/修改本地IP

    1 前言 好久没动Win10了... 今天需要用Win10做一下实验,手动修改IP,于是写下了这篇文章作为过程记录. 2 概述 Win10里面修改本地IP不是一件特别困难的事,简单来说可以分为两种方式 ...