CodeForces 670D
2016-05-08 23:21
302 查看
题意:给你一个长度为n的数组来构造出一个矩阵,其中对角线的值是-1,Aij的值就是a[i]&a[j],现在给出这个矩阵,求出原来的数组
思路:其实直接|每一行就是每个i的值了嘛
Description
Recently Polycarpus has learned the "bitwise AND" operation (which is also called "AND") of non-negative integers. Now he wants to demonstrate the school IT teacher his superb manipulation with the learned operation.
For that Polycarpus came to school a little earlier and wrote on the board a sequence of non-negative integers a1, a2, ..., an.
He also wrote a square matrix b of size n × n. The element of matrix b that
sits in the i-th row in the j-th column (we'll denote it as bij)
equals:
the "bitwise AND" of numbers ai and aj (that
is, bij = ai & aj), if i ≠ j;
-1, if i = j.
Having written out matrix b, Polycarpus got very happy and wiped a off the blackboard. But the thing is, the teacher will want
this sequence to check whether Polycarpus' calculations were correct. Polycarus urgently needs to restore the removed sequence of integers, or else he won't prove that he can count correctly.
Help Polycarpus, given matrix b, restore the sequence of numbers a1, a2, ..., an,
that he has removed from the board. Polycarpus doesn't like large numbers, so any number in the restored sequence mustn't exceed 109.
Input
The first line contains a single integer n(1 ≤ n ≤ 100) — the size of square matrix b.
Next n lines contain matrix b. The i-th of these lines contains n space-separated
integers: the j-th number represents the element of matrix bij. It is guaranteed, that
for all i(1 ≤ i ≤ n)the following condition fulfills: bii =
-1. It is guaranteed that for all i, j(1 ≤ i, j ≤ n; i ≠ j) the following condition
fulfills: 0 ≤ bij ≤ 109, bij = bji.
Output
Print n non-negative integers a1, a2, ..., an(0 ≤ ai ≤ 109) —
the sequence that Polycarpus wiped off the board. Separate the numbers by whitespaces.
It is guaranteed that there is sequence a that satisfies the problem conditions. If there are multiple such sequences, you are allowed to print any of them.
Sample Input
Input
Output
Input
Output
Input
Output
Hint
If you do not know what is the "bitwise AND" operation please read: http://en.wikipedia.org/wiki/Bitwise_operation.
思路:其实直接|每一行就是每个i的值了嘛
#include<bits\stdc++.h> using namespace std; int mp[105][105]; int a[105]; int main() { int n; scanf("%d",&n); for (int i = 1;i<=n;i++) { for (int j = 1;j<=n;j++) { scanf("%d",&mp[i][j]); if(i!=j) a[i]|=mp[i][j]; } } for (int i = 1;i<=n;i++) printf("%d ",a[i]); printf("\n"); }
Description
Recently Polycarpus has learned the "bitwise AND" operation (which is also called "AND") of non-negative integers. Now he wants to demonstrate the school IT teacher his superb manipulation with the learned operation.
For that Polycarpus came to school a little earlier and wrote on the board a sequence of non-negative integers a1, a2, ..., an.
He also wrote a square matrix b of size n × n. The element of matrix b that
sits in the i-th row in the j-th column (we'll denote it as bij)
equals:
the "bitwise AND" of numbers ai and aj (that
is, bij = ai & aj), if i ≠ j;
-1, if i = j.
Having written out matrix b, Polycarpus got very happy and wiped a off the blackboard. But the thing is, the teacher will want
this sequence to check whether Polycarpus' calculations were correct. Polycarus urgently needs to restore the removed sequence of integers, or else he won't prove that he can count correctly.
Help Polycarpus, given matrix b, restore the sequence of numbers a1, a2, ..., an,
that he has removed from the board. Polycarpus doesn't like large numbers, so any number in the restored sequence mustn't exceed 109.
Input
The first line contains a single integer n(1 ≤ n ≤ 100) — the size of square matrix b.
Next n lines contain matrix b. The i-th of these lines contains n space-separated
integers: the j-th number represents the element of matrix bij. It is guaranteed, that
for all i(1 ≤ i ≤ n)the following condition fulfills: bii =
-1. It is guaranteed that for all i, j(1 ≤ i, j ≤ n; i ≠ j) the following condition
fulfills: 0 ≤ bij ≤ 109, bij = bji.
Output
Print n non-negative integers a1, a2, ..., an(0 ≤ ai ≤ 109) —
the sequence that Polycarpus wiped off the board. Separate the numbers by whitespaces.
It is guaranteed that there is sequence a that satisfies the problem conditions. If there are multiple such sequences, you are allowed to print any of them.
Sample Input
Input
1 -1
Output
0
Input
3
-1 18 0
18 -1 0
00-1
Output
18 18 0
Input
4
-1 128 128 128
128 -1 148 160
128 148 -1 128
128 160128 -1
Output
128 180148 160
Hint
If you do not know what is the "bitwise AND" operation please read: http://en.wikipedia.org/wiki/Bitwise_operation.
相关文章推荐
- VOLTE parameter in Attach Request/Accept message
- 智能算法---模拟退火搜索函数最小值
- 动态链接库DLL
- 20145321 实验五实验报告
- CUDA学习笔记三
- 搜狗补刀推出搜狗明医
- 搜狗补刀推出搜狗明医
- Toy Program 基础线程入门 via “extends Thread”
- Jmeter之csv、用户自定义变量以及Query Type分析(八)
- CodeForces 670C Cinema
- 对于已经存在的项目,如何在不改变原来目录结构的情况下,使用maven
- Agent proxy
- hdu-2066 一个人的旅行(最短路spfa)
- java第十周学习总结
- 隐马尔可夫模型学习笔记
- Adnroid多媒体---图片
- JS学习10(DOM扩展)
- 详解Android中Drawable方法
- CodeForces 670B Game of Robots
- Android之Volley框架加载网络图片的三种方式