Codeforces Round #368 (Div. 2) A , B , C
2 seconds
256 megabytes
standard input
standard output
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour!
As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white.
Photo can be represented as a matrix sized n × m, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors:
- 'C' (cyan)
- 'M' (magenta)
- 'Y' (yellow)
- 'W' (white)
- 'G' (grey)
- 'B' (black)
The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored.
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of photo pixel matrix rows and columns respectively.
Then n lines describing matrix rows follow. Each of them contains m space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'.
Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
2 2
C M
Y Y
#Color
3 2
W W
W W
B B
#Black&White
1 1
W
#Black&White
题意:六种颜色;
如果有C' (cyan),'M' (magenta),'Y' (yellow)三种任意一种输出#Color;
否则输出#Black&White;
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define esp 0.00000000001
#define pi 4*atan(1)
const int N=1e5+,M=1e6+,inf=1e9+,mod=1e9+;
int main()
{
int x,y,z,i,t;
scanf("%d%d",&x,&y);
int ans=;
for(i=;i<x;i++)
{
for(t=;t<y;t++)
{
char a;
cin>>a;
if(a=='Y'||a=='M'||a=='C')
ans=;
}
}
if(ans)
printf("#Color\n");
else
printf("#Black&White\n");
return ;
}
2 seconds
256 megabytes
standard input
standard output
Masha wants to open her own bakery and bake muffins in one of the n cities numbered from 1 to n. There are m bidirectional roads, each of whose connects some pair of cities.
To bake muffins in her bakery, Masha needs to establish flour supply from some storage. There are only k storages, located in different cities numbered a1, a2, ..., ak.
Unforunately the law of the country Masha lives in prohibits opening bakery in any of the cities which has storage located in it. She can open it only in one of another n - k cities, and, of course, flour delivery should be paid — for every kilometer of path between storage and bakery Masha should pay 1 ruble.
Formally, Masha will pay x roubles, if she will open the bakery in some city b (ai ≠ b for every 1 ≤ i ≤ k) and choose a storage in some city s (s = aj for some 1 ≤ j ≤ k) and b and s are connected by some path of roads of summary length x (if there are more than one path, Masha is able to choose which of them should be used).
Masha is very thrifty and rational. She is interested in a city, where she can open her bakery (and choose one of k storages and one of the paths between city with bakery and city with storage) and pay minimum possible amount of rubles for flour delivery. Please help Masha find this amount.
The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 105, 0 ≤ k ≤ n) — the number of cities in country Masha lives in, the number of roads between them and the number of flour storages respectively.
Then m lines follow. Each of them contains three integers u, v and l (1 ≤ u, v ≤ n, 1 ≤ l ≤ 109, u ≠ v) meaning that there is a road between cities u and v of length of l kilometers .
If k > 0, then the last line of the input contains k distinct integers a1, a2, ..., ak (1 ≤ ai ≤ n) — the number of cities having flour storage located in. If k = 0 then this line is not presented in the input.
Print the minimum possible amount of rubles Masha should pay for flour delivery in the only line.
If the bakery can not be opened (while satisfying conditions) in any of the n cities, print - 1 in the only line.
5 4 2
1 2 5
1 2 3
2 3 4
1 4 10
1 5
3
3 1 1
1 2 3
3
-1
题意:给你n个点,m条边,k个货舱;
除了货舱就是商店,问某一个货舱到某一个商店的最短距离;
思路:直接遍历一遍边即可;
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define esp 0.00000000001
#define pi 4*atan(1)
const int N=1e5+,M=1e6+,inf=1e9+,mod=1e9+;
int flag[N];
struct is
{
int u,v,w;
}a[N];
int check(int x,int y)
{
if(flag[x]!=flag[y])
return ;
return ;
}
int main()
{
int x,y,z,i,t;
scanf("%d%d%d",&x,&y,&z);
for(i=;i<y;i++)
scanf("%d%d%d",&a[i].u,&a[i].v,&a[i].w);
for(i=;i<z;i++)
{
scanf("%d",&t);
flag[t]=;
}
int ans=inf;
for(i=;i<y;i++)
{
if(check(a[i].u,a[i].v))
{
ans=min(ans,a[i].w);
}
}
if(ans==inf)
printf("-1\n");
else
printf("%d\n",ans);
return ;
}
1 second
256 megabytes
standard input
standard output
Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples.
For example, triples (3, 4, 5), (5, 12, 13) and (6, 8, 10) are Pythagorean triples.
Here Katya wondered if she can specify the length of some side of right triangle and find any Pythagorean triple corresponding to such length? Note that the side which length is specified can be a cathetus as well as hypotenuse.
Katya had no problems with completing this task. Will you do the same?
The only line of the input contains single integer n (1 ≤ n ≤ 109) — the length of some side of a right triangle.
Print two integers m and k (1 ≤ m, k ≤ 1018), such that n, m and k form a Pythagorean triple, in the only line.
In case if there is no any Pythagorean triple containing integer n, print - 1 in the only line. If there are many answers, print any of them.
3
4 5
6
8 10
1
-1
17
144 145
67
2244 2245
题意:给出一直角三角形的某一边输出另外两条整数边,构成直角三角形;
关于一直角边为素数的整边直角三角形的两个性质
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define esp 0.00000000001
#define pi 4*atan(1)
const int N=1e5+,M=1e6+,inf=1e9+,mod=1e9+;
int prime(int n)
{
if(n<=)
return ;
if(n==)
return ;
if(n%==)
return ;
int k, upperBound=n/;
for(k=; k<=upperBound; k+=)
{
upperBound=n/k;
if(n%k==)
return ;
}
return ;
}
ll p[N],hh;
ll getans(ll x)
{
return (x*x-)/;
}
void init()
{
hh=;
for(int i=;i<=;i++)
if(prime(i))
p[hh++]=i;
}
int main()
{
ll x,y,z,i,t;
init();
scanf("%lld",&x);
if(x<=)
{
printf("-1\n");
return ;
}
if(x%==)
{
printf("%lld %lld\n",x/*,x/*);
return ;
}
int gg=;
if(x%==)
x/=,gg=;
for(i=;i<hh;i++)
{
if(x%p[i]==)
{
ll ans=getans(p[i]);
printf("%lld %lld\n",x/p[i]*ans*gg,x/p[i]*(ans+)*gg);
return ;
}
}
ll ans=getans(x);
printf("%lld %lld\n",ans*gg,(ans+)*gg);
return ;
}
Codeforces Round #368 (Div. 2) A , B , C的更多相关文章
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- Codeforces Round #368 (Div. 2) C. Pythagorean Triples(数学)
Pythagorean Triples 题目链接: http://codeforces.com/contest/707/problem/C Description Katya studies in a ...
- Codeforces Round #368 (Div. 2) B. Bakery (模拟)
Bakery 题目链接: http://codeforces.com/contest/707/problem/B Description Masha wants to open her own bak ...
- Codeforces Round #368 (Div. 2) A. Brain's Photos (水题)
Brain's Photos 题目链接: http://codeforces.com/contest/707/problem/A Description Small, but very brave, ...
- Codeforces Round #368 (Div. 2) D. Persistent Bookcase
Persistent Bookcase Problem Description: Recently in school Alina has learned what are the persisten ...
- Codeforces Round #368 (Div. 2)D. Persistent Bookcase DFS
题目链接:http://codeforces.com/contest/707/my 看了这位大神的详细分析,一下子明白了.链接:http://blog.csdn.net/queuelovestack/ ...
- Codeforces Round #368 (Div. 2) E. Garlands 二维树状数组 暴力
E. Garlands 题目连接: http://www.codeforces.com/contest/707/problem/E Description Like all children, Ale ...
- Codeforces Round #368 (Div. 2) D. Persistent Bookcase 离线 暴力
D. Persistent Bookcase 题目连接: http://www.codeforces.com/contest/707/problem/D Description Recently in ...
- Codeforces Round #368 (Div. 2) C. Pythagorean Triples 数学
C. Pythagorean Triples 题目连接: http://www.codeforces.com/contest/707/problem/C Description Katya studi ...
- Codeforces Round #368 (Div. 2) B. Bakery 水题
B. Bakery 题目连接: http://www.codeforces.com/contest/707/problem/B Description Masha wants to open her ...
随机推荐
- c#文件流汇总
操作文件比较常见,项目中经常出现这样的需求:按每个月自动创建文件,并且向文件里面插入一些数据,那么我们将要分析,文件是否存在的情况:如果存在则直接打开文件流向文件中插入数据,如果不存在,则创建文件再插 ...
- angularjs 复选框 单选框
关于复选框,在做项目的时候,有一下几点心得 单选框 1.判断哪个单选框选中的情况 html代码 判断该复选框是否选中 $scope.agree.isChecked 判断这个值,如果等于1,代表 ...
- echarts, 小知识点随意记录,
注意点: 写echarts代码时,注意格式,每个项的子项用‘,‘分隔,最后一项不需要.如符号不也会造成图形显示不出来.写时注意参照配置项. 如下orient的属性需要单引号,每个项需要逗号等. leg ...
- 系统盘的消耗 谨慎的日志存储到系统盘+日志级别!! 569 error_log = /usr/local/php7/logs/php-error.log 26 error_log = /usr/local/php7/logs/fpm_error_log
案例: 系统盘一夜之间骤增近20G nginx + php-fpm cat /usr/local/nginx/conf/nginx.conf 查看对请求的处理 4个配置文件 /usr/local/n ...
- NoSQL 数据库分类 颠覆
NoSQL 数据库分类 类型 部分代表特点 列存储 HbaseCassandraHypertable顾名思义,是按列存储数据的.最大的特点是方便存储结构化和半结构化数据,方便做数据压缩,对针对某一列或 ...
- python系列十五:Python3 错误和异常
#!/usr/bin/python #-*-coding:gbk-*- #Python3 错误和异常'''Python 语法错误或者称之为解析错语法分析器指出了出错的一行,并且在最先找到的错误的位置标 ...
- Centos简介(一)
Centos作为主流的一种Linux操作系统,我们选用Centos,主要是免费,以及稳定. Centos详细介绍,请参考 百度百科
- spring和hibernate整合时设置自动生成数据库的表
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFa ...
- python基础里的那些为什么?
一.执行python脚本的两种方式? 直接在解释器里编写并在解释器里执行 文件编写,并在终端通过 python 路径 这种方式执行 好,我们就以输出hello world这个例子来比较两种方式的不同 ...
- C 和 C++ 的标准库分别有自己的 locale 操作方法,C 标准库的 locale 设定函数是 setlocale(),而 C++ 标准库有 locale 类和流对象的 imbue() 方法(gcc使用zh_CN.GBK,或者zh_CN.UTF-8,VC++使用Chinese_People's Republic of China.936或者65001.)
转自:http://zyxhome.org/wp/cc-prog-lang/c-stdlib-setlocale-usage-note/ [在此向原文作者说声谢谢!若有读者看到文章转载时请写该转载地址 ...