Codeforces707Div2
A
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.
输入一个颜色矩阵问,是不是黑白的.
傻逼题,不解释
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#define il inline
#define re register
using namespace std;
int n,m;
int main(){
scanf("%d%d",&n,&m);
char str[];
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
scanf("%s",str);
if(str[]=='C'||str[]=='M'||str[]=='Y'){
cout<<"#Color";return ;
}
}
}
cout<<"#Black&White";
return ;
}
B
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 ≤ 10^5, 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 ≤ 10^9, 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.
无向图图中有特殊点,问特殊点到非特殊点的最短距离
显然这是链接两个点集的一条边
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#define il inline
#define re register
using namespace std;
struct edge{int next,to,val;
} e[];
int n,m,k,a[],ans=(<<),M,g[];
il void addedge(int x,int y,int z){
e[++M]=(edge){g[x],y,z};g[x]=M;
}
int main(){
scanf("%d%d%d",&n,&m,&k);
for(int i=,x,y,z;i<=m;i++){
scanf("%d%d%d",&x,&y,&z);
addedge(x,y,z);
addedge(y,x,z);
}
for(int i=,x;i<=k;i++){
scanf("%d",&x);a[x]=;
}
for(int i=;i<=n;i++) if(!a[i]){
for(int j=g[i];j;j=e[j].next) if(a[e[j].to]){
ans=min(ans,e[j].val);
}
}
if(ans<(<<)) cout<<ans;
else cout<<"-1";
return ;
}
C
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 calledPythagorean 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 ≤ 10^9) — the length of some side of a right triangle.
Print two integers m and k (1 ≤ m, k ≤ 10^18), 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.
输入直角三角形的一条边,构造其它两条边,使得能构成一个直角三角形。
如果n是一个奇数 三角形分别是 n (n^2-1)/2 (n^2+1)/2
如果n是一个偶数 三角形分别是 n (n*n/4-1) (n*n/4+1)
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#define il inline
#define re register
using namespace std;
long long n;
int main(){
cin>>n;
if(n<){
cout<<"-1";
}
else if(n&){
cout<<(n*n-)/<<" "<<(n*n+)/;
}
else{
n/=;
cout<<(n*n-)<<" "<<(n*n+);
}
return ;
}
D
Recently in school Alina has learned what are the persistent data structures: they are data structures that always preserves the previous version of itself and access to it when it is modified.
After reaching home Alina decided to invent her own persistent data structure. Inventing didn't take long: there is a bookcase right behind her bed. Alina thinks that the bookcase is a good choice for a persistent data structure. Initially the bookcase is empty, thus there is no book at any position at any shelf.
The bookcase consists of n shelves, and each shelf has exactly m positions for books at it. Alina enumerates shelves by integers from 1to n and positions at shelves — from 1 to m. Initially the bookcase is empty, thus there is no book at any position at any shelf in it.
Alina wrote down q operations, which will be consecutively applied to the bookcase. Each of the operations has one of four types:
- 1 i j — Place a book at position j at shelf i if there is no book at it.
- 2 i j — Remove the book from position j at shelf i if there is a book at it.
- 3 i — Invert book placing at shelf i. This means that from every position at shelf i which has a book at it, the book should be removed, and at every position at shelf i which has not book at it, a book should be placed.
- 4 k — Return the books in the bookcase in a state they were after applying k-th operation. In particular, k = 0 means that the bookcase should be in initial state, thus every book in the bookcase should be removed from its position.
After applying each of operation Alina is interested in the number of books in the bookcase. Alina got 'A' in the school and had no problem finding this values. Will you do so?
The first line of the input contains three integers n, m and q (1 ≤ n, m ≤ 10^3, 1 ≤ q ≤ 10^5) — the bookcase dimensions and the number of operations respectively.
The next q lines describes operations in chronological order — i-th of them describes i-th operation in one of the four formats described in the statement.
It is guaranteed that shelf indices and position indices are correct, and in each of fourth-type operation the number k corresponds to some operation before it or equals to 0.
For each operation, print the number of books in the bookcase after applying it in a separate line. The answers should be printed in chronological order.
要求你实现一个矩阵,使得其满足以下操作
1. 将给定矩阵位置的值改为1
2. 将给定矩阵位置的值改为0
3. 翻转这个矩阵的一行
4. 把矩阵恢复到第k次操作之后
离线操作,将版本建成一棵树,每次暴力处理即可
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#define il inline
#define re register
using namespace std;
const int N=;
int n,m,Q,k[N],x[N],y[N],tag[],a[][],sum[],ans,fin[N];
vector<int> g[N];
il void flip(int x){
tag[x]^=;
ans+=m-sum[x]-sum[x];
sum[x]=m-sum[x];
}
il void dfs(re int h){
fin[h]=ans;
if(k[h+]!=&&h<Q){
if(k[h+]==){
flip(x[h+]);
dfs(h+);
flip(x[h+]);
}
else if(k[h+]==){
if(a[x[h+]][y[h+]]^tag[x[h+]]==){
sum[x[h+]]++;ans++;
a[x[h+]][y[h+]]^=;
dfs(h+);
a[x[h+]][y[h+]]^=;
sum[x[h+]]--;ans--;
}
else dfs(h+);
}
else if(k[h+]==){
if(a[x[h+]][y[h+]]^tag[x[h+]]==){
sum[x[h+]]--;ans--;
a[x[h+]][y[h+]]^=;
dfs(h+);
a[x[h+]][y[h+]]^=;
sum[x[h+]]++;ans++;
}
else dfs(h+);
}
}
for(re int i=g[h].size()-;i>=;i--){
// cout<<h<<" "<<"=="<<ans<<endl;
dfs(g[h][i]);
} }
int main(){
scanf("%d%d%d",&n,&m,&Q);
for(int i=;i<=Q;i++){
scanf("%d%d",&k[i],&x[i]);
if(k[i]==){
g[x[i]].push_back(i);
}
else{
if(k[i]<) scanf("%d",&y[i]);
}
}
dfs();
for(int i=;i<=Q;i++)
printf("%d\n",fin[i]);
return ;
}
Codeforces707Div2的更多相关文章
随机推荐
- 【RAC搭建报错】在RAC搭建到grid安装前的检查时,报错
这种ip的报错,无非是检查防火墙,ip配置的原因 而我防火墙已关闭,ip也没配错 最后的原因是因为我172.16.1.41/42这两个IP选的虚拟机没有配置网段 [grid@rac01 grid]$ ...
- DataTable保存与读取 stream
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...
- Linux☞如何修改文件权限
修改文件/目录的权限:chmod 规则 文件/目录名 规则: 角色:u 自己人 user g 同组人 group o 其他人 other a 所有人 all 操作: + - 权限 ...
- 百度地图之自动提示--autoComplete
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- UTF-8编码下'\u7528\u6237'转换为中文汉字'用户'
UTF-8编码下'\u7528\u6237'转换为中文'用户' 一.前言 有过多次,在开发项目中遇见设置文件编码格式为UTF-8,但是打开该文件出现类似\u7528这样的数据,看也看不懂,也不是平常见 ...
- leetcode26_C++删除排序数组中的重复项
给定一个排序数组,你需要在原地删除重复出现的元素,使得每个元素只出现一次,返回移除后数组的新长度. 不要使用额外的数组空间,你必须在原地修改输入数组并在使用 O(1) 额外空间的条件下完成. 示例 1 ...
- mtv网站架构模式适合企业网站应用吗?
mtv网站架构模式适合企业网站应用吗?有时候在思考这样一个问题. 从开发角度来说,本来mvc的进度慢了些,如果在数据库管理方面用sql的话,管理起来也不很方便.小企业网本来数据就不很多,也没什么太多安 ...
- 定制自己的动画 View 控件(Canvas 使用)
定制自己的动画 View 控件(Canvas 使用) 如果要定义自己的 View 控件,则需要新建一个类继承 android.view.View.然后在 onDraw 中写自己需要实现的方式. 这里定 ...
- Android源码项目目录结构
src: 存放java代码 gen: 存放自动生成文件的. R.java 存放res文件夹下对应资源的id project.properties: 指定当前工程采用的开发工具包的版本 libs: 当前 ...
- Eclipse项目导入到Android Studio中
背景 最近需要将Eclipse中的android项目导入到Android Studio中!倒腾一番,记录如下! 步骤1 打开Android Studio(下文称AS),选择Import project ...