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
题解:
很水的一道题,居然能被cha。
代码:
<span style="font-size:14px;">#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <vector>
#include <map>
#include <algorithm>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define mem(a) memset(a, 0, sizeof(a))
#define eps 1e-5
#define MAX 400030
#define INF 0x3f3f3f3f
#define long long LL
using namespace std;
int t,a,b;
char c[2];
int main()
{
scanf("%d%d",&a,&b);
int aa;
aa=0;
for(int i=0;i<a;i++)
{
for(int j=0;j<b;j++)
{
cin>>c;
if(c[0]=='C')
aa=1;
if(c[0]=='M')
aa=1;
if(c[0]=='Y')
aa=1;
}
}
if(aa)
cout<<"#Color"<<endl;
else
cout<<"#Black&White"<<endl;
}
</span>
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

Image illustrates the first sample case. Cities with storage located in and the road representing the answer are darkened.
题意;n个点,m条双向边,k个特殊点,问找到非特殊点到特殊点的最短距离,没有输出-1.
题解:
枚举每个特殊点到非特殊点的距离,维护答案,由于点过多,申请二维数组存距离是不可能的,我们用vector+结构体。
代码:
<span style="font-size:14px;">#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <vector>
#include <map>
#include <algorithm>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define mem(a) memset(a, 0, sizeof(a))
#define eps 1e-5
#define MAX 400030
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;
LL n,m,k;
struct point
{
int x,y;
point(int xx,int yy)
{
x=xx,y=yy;
}
};
vector<point> dian[100004];
int vis[100004];
int main()
{
int l,r,d;
scanf("%ld%ld%ld",&n,&m,&k);
for(int i=1;i<=n;i++)
dian[i].clear();
for(int i=1;i<=m;i++)
{
scanf("%d%d%d",&l,&r,&d);
dian[l].push_back(point(r,d));
dian[r].push_back(point(l,d));
}
mem(vis);
for(int i=1;i<=k;i++)
{
scanf("%d",&d);
vis[d]=1;
}
int ans=INF;
for(int i=1;i<=n;i++)
{
if(vis[i])
{
for(int j=0;j<dian[i].size();j++)
{
if(!vis[dian[i][j].x])
ans=min(ans,dian[i][j].y);
}
}
}
if(ans==INF)
cout<<-1<<endl;
else
cout<<ans<<endl;
}</span>
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

Illustration for the first sample.
题意:给出直角三角形的一条直角边,问另一条直角边和斜边的值。多解输出任意一个,无解输出-1.
题解;
当给出的边长度小于3时无解.
设另外两条边长分别为a,b,其中b是斜边
由勾股定理可以得出:a*a+n*n=b*b
公式稍作调整:(b-a)(b+a)=n*n
当n为奇数时,只需要使得b-a=1,b+a=n*n即可。
当n为偶数时,只需要使得b-a=2,b+a=n*n/2即可。
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <vector>
#include <map>
#include <algorithm>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define mem(a) memset(a, 0, sizeof(a))
#define eps 1e-5
#define MAX 400030
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;
LL a;
int main()
{
cin>>a;
if(a<3)
{
cout<<-1<<endl;
return 0;
}
if(a%2)
{
LL b=a*a/2;
LL c=b+1;
cout<<b<<" "<<c<<endl;
}
else
{
LL b=a*a/4-1;
LL c=b+2;
cout<<b<<" "<<c<<endl;
}
}