int main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int n;cin>>n; for(int i=0;i;i++)cin>>s[i]; for(int i=0;i;i++)cin>>a[i]; for(int i=0;i;i++)cin>>b[i]; for(int i=0;i;i++){ c[i]+=s[i]...
题目描述

输入描述

输出描述

输入样例
32
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

输出样例
0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

提示
特别注意：输出的 Vci 只能为 0 / 1 。

题目大意： 给定符号位数组 sgn [ ] ，及数组 Va [ ] , Vb [ ] 表示数值 a 和 b 的各个数位，现规定数值 a ，b 的计算方式为题中公式，需求 a + b 后所得的答案 c 通过该公式转化后表示各个数位的 Vc [ ] 数组。
不难发现本题公式中 2 的 i 次方正好反应了二进制对应每一位的权值，得到的结果为：高位在右侧，低位在左侧。即对于序列 1110 ，对应后 a 的值为 0111 ，而 sgn [ ] 为控制每一位的符号。

因此本题的计算方式即可转化为（仅考虑符号位都为 + 1 时）：对数组 Va 和 Vb 由低位向高位进行该位的相加及进位，处理后得到的每一位的答案即为 Vc 的对应位，由此样例可得：1 + 111 = 1000（该运算过程中前导 0 均省略），将 1000 倒序输出后即可。
当符号位存在 - 1 时，为了方便辨别 Vc 中对应位的正负，可在 Vc [ ] 数组中添加负号加以区分，例（此处规定的数组下标是为了更好演示示例）：① sgn [ i ] = - 1，Va [ i ] = 1，Vb [ i ] = 0 时，Vc [ i ] = - 1；② sgn [ i ] = - 1，Va [ i ] = 1，Vb [ i ] = 1 时，Vc [ i ] = 0 ，Vc [ i + 1] 由于进位 = - 1 ；
然而，由于输出的 Vc 只能为 0 / 1，因此需要对存在 - 1 可能性的原 Vc 数组进行变换，以下通过三种情况进行分类讨论。
其中，例 1 与 2 、3 的区别为：对于处理完进位但仍存在符号的数组 c ，是否存在与数组 sgn 符号相反（即其中一个为 - 1，另一为 + 1）的情况，而当出现该情况时，需要进行特殊处理，否则直接取该位的绝对值即可。
例 2 中，由于位权 2 的进位使位权 4 中出现了数组 c 与符号位 sgn 相反的情况。本样例中，由于 a、b 都含有位权 2 ，因此对 c 的贡献应为 （ + 2 ）+ （ + 2 ），进位后应取 （ + 4 ），但由于位权 4 的符号位 sgn 为 - 1 ，因此此处对 c 的贡献为（ - 4 ）。而由于符号位 sgn 的值已经确定，因此只能通过配凑的方式使得对 c 的贡献仍然为（ + 4 ），即令后一位（ 位权 8 ）进行 加一 处理， 得到（ + 8 ）+（ - 4 ）=（ + 4 ）；
同理，在例 3 中，由于位权 8 处的符号相反，因此需要令（ - 16 ） +（ + 8 ）=（ - 8 ）进行配凑，即令后一位进行 减一 处理。而由于连锁反应，位权 16 又会将 - 2 进行进位，直到该操作对后续位再无影响为止。
因此本题的核心为判断数组 c [ ] 与数组 sgn [ ] 是否相反，当 sgn = 1 且 c = - 1 时，对后一位进行 - 1 处理；当 sgn = - 1 且 c = 1 时，对后续位进行 + 1 处理，并不断对后续进行遍历保证其合法性。
参考代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100;
int a[N],b[N],s[N],ans[N],c[N];

int main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int n;cin>>n;
for(int i=0;i<n;i++)cin>>s[i];
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<n;i++)cin>>b[i];
for(int i=0;i<n;i++){
c[i]+=s[i]*a[i]+s[i]*b[i];
if(c[i]>=2){
c[i]=c[i]%2;
c[i+1]++;
}
if(c[i]<=-2){
c[i]=c[i]+2;
c[i+1]--;
}
}
for(int i=0;i<n;i++){
if(s[i]==-1&&c[i]==-1)ans[i]=1;
if(s[i]==1&&c[i]==1)ans[i]=1;
if(c[i]==0)ans[i]=0;
if(s[i]==-1&&c[i]==1){
ans[i]=1;
c[i+1]++;
for(int j=1;j+i<n;j++){
if(c[i+j]==2){
c[i+j]=0;
c[i+j+1]++;
}else break;
}
}

if(s[i]==1&&c[i]==-1){
ans[i]=1;
c[i+1]--;
for(int j=1;j+i<n;j++){
if(c[i+j]==-2){
c[i+j]=0;
c[i+j+1]--;
}else break;
}

}
}

for(int i=0;i<n;i++){
cout<<ans[i];
if(i!=n-1)
cout<<' ';
}
return 0;
}


展开全文
laysan 2021-09-25 23:25:00
• ## A. Mathematical Addition c++ c语言

Mathematical Addition time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Ivan decided to prepare for the test on solving integer ...
A. Mathematical Addition
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form:
You are given two positive integers uu and vv, find any pair of integers (not necessarily positive) xx, yy, such that: xu+yv=x+yu+v.xu+yv=x+yu+v. The solution x=0x=0, y=0y=0 is forbidden, so you should find any solution with (x,y)≠(0,0)(x,y)≠(0,0).
Input
The first line contains a single integer tt (1≤t≤1031≤t≤103) — the number of test cases. The next lines contain descriptions of test cases.
The only line of each test case contains two integers uu and vv (1≤u,v≤1091≤u,v≤109) — the parameters of the equation.
Output
For each test case print two integers xx, yy — a possible solution to the equation. It should be satisfied that −1018≤x,y≤1018−1018≤x,y≤1018 and (x,y)≠(0,0)(x,y)≠(0,0).
We can show that an answer always exists. If there are multiple possible solutions you can print any.
Example
input
Copy
4
1 1
2 3
3 5
6 9

output
Copy
-1 1
-4 9
-18 50
-4 9

思路：求出x.y与u.v的关系表达式

#include<iostream>
#include<algorithm>

using namespace std;

int t, m;

int main()
{
long long u, v;
scanf("%d",&t);

while(t --)
{
scanf("%lld%lld", &u, &v);

long long x = 0 - u * u;
long long y = v * v;

printf("%lld %lld\n", x, y);
}
return 0;
}

（萌新上路，有更好的方法或者写的有问题可以多多交流）
展开全文
m0_60610120 2021-11-24 21:10:51
• However, since you are calling the method from an instance, it is a bound method, and thus receives the instance as the first argument (the self parameter), in addition to all the other arguments....


I'm having some trouble understanding why the following code does not pass:
test.py
import mock
import unittest
from foo import Foo
class TestFoo(unittest.TestCase):
@mock.patch('foo.Bar')
foo = Foo()
if __name__ == '__main__':
unittest.main()
foo.py
from bar import Bar
class Foo(object):
bar = Bar()
bar.py
class Bar(object):
print('b.Bar --> Adding {} + {}'.format(x, y))
return x + y
In the code, Foo.add creates an instance of Bar and returns the result of Bar.add when invoked. Why does testing assert_called_with for Bar.add fail? I believe I am mocking the Bar in the correct place (I am mocking foo.Bar because that is the namespace which it is being looked up, rather than bar.Bar).
Traceback (most recent call last):
File "/Users/iain/PycharmProjects/testing/venv/lib/python2.7/site-packages/mock.py", line 1201, in patched
return func(*args, **keywargs)
File "test.py", line 12, in test_a_b
File "/Users/iain/PycharmProjects/testing/venv/lib/python2.7/site-packages/mock.py", line 831, in assert_called_with
raise AssertionError('Expected call: %s\nNot called' % (expected,))
Not called
解决方案
You are mocking the method call in the right place. However, since you are calling the method from an instance, it is a bound method, and thus receives the instance as the first argument (the self parameter), in addition to all the other arguments.
Edit: Since Bar is replaced with a Mock instance, Bar().add does not know it's a method (and hence is not bound to anything). In other words, Bar is a Mock, Bar() is a Mock, and Bar().add is also a Mock. bar.add is thus a newly created mock, called with arguments (2, 2). One way of asserting this call would be:
@mock.patch('foo.Bar')
foo = Foo()
Depending on how your actual code looks, you may want to instead mock the method rather than the class:
foo = Foo()

展开全文
weixin_39610631 2021-07-19 18:52:54
• 4g Ho 5g1. 5.3.3 Connection Management5.3.3.1 General5.3.3.2 5GS Connection Management states5.3.3.2.1 General5.3.3.2.2 CM-IDLE state5.3.3.2.3 CM-CONNECTED state5.3....CONNECTED with RRC Inactive state


4g Ho 5g
1. 5.3.3 Connection Management5.3.3.1 General5.3.3.2 5GS Connection Management states5.3.3.2.1 General5.3.3.2.2 CM-IDLE state5.3.3.2.3 CM-CONNECTED state5.3.3.2.4 5GS Connection Management State models5.3.3.2.5 CM-CONNECTED with RRC Inactive state

1. 5.3.3 Connection Management
5.3.3.1 General
Connection management comprises the functions of establishing and releasing a NAS signalling connection between a UE and the AMF over N1. This NAS signalling connection is used to enable NAS signalling exchange between the UE and the core network. It comprises both the AN signalling connection between the UE and the AN (RRC Connection over 3GPP access or UE-N3IWF connection over untrusted N3GPP access or UE-TNGF connection over trusted N3GPP access) and the N2 connection for this UE between the AN and the AMF.
5.3.3.2 5GS Connection Management states
5.3.3.2.1 General
Two CM states are used to reflect the NAS signalling Connection of the UE with the AMF:
CM-IDLECM-CONNECTED The CM state for 3GPP access and Non-3GPP access are independent of each other, i.e. one can be in CM-IDLE state at the same time when the other is in CM-CONNECTED state.
5.3.3.2.2 CM-IDLE state
A UE in CM-IDLE state has no NAS signalling connection established with the AMF over N1. The UE performs cell selection/cell reselection according to TS 38.304 [50] and PLMN selection according to TS 23.122 [17]. There are no AN signalling connection, N2 connection and N3 connections for the UE in the CM-IDLE state. If the UE is both in CM-IDLE state and in RM-REGISTERED state, the UE shall, unless otherwise specified in clause 5.3.4.1:
Respond to paging by performing a Service Request procedure (see TS 23.502 [3] clause 4.2.3.2), unless the UE is in MICO mode (see clause 5.4.1.3);perform a Service Request procedure when the UE has uplink signalling or user data to be sent (see TS 23.502 [3] clause 4.2.3.2). Specific conditions apply for LADN, see clause 5.6.5. When the UE state in the AMF is RM-REGISTERED, UE information required for initiating communication with the UE shall be stored. The AMF shall be able to retrieve stored information required for initiating communication with the UE using the 5G-GUTI. NOTE: In 5GS there is no need for paging using the SUPI/SUCI of the UE. The UE provides 5G-S-TMSI as part of AN parameters during AN signalling connection establishment as specified in TS 38.331 [28] and TS 36.331 [51]. The UE shall enter CM-CONNECTED state whenever an AN signalling connection is established between the UE and the AN (entering RRC Connected state over 3GPP access, or at the establishment of the UE-N3IWF connectivity over untrusted non-3GPP access or the UE-TNGF connectivity over trusted non-3GPP access). The transmission of an Initial NAS message (Registration Request, Service Request or Deregistration Request) initiates the transition from CM-IDLE to CM-CONNECTED state. When the UE states in the AMF are CM-IDLE and RM-REGISTERED, the AMF shall:perform a network triggered Service Request procedure when it has signalling or mobile-terminated data to be sent to this UE, by sending a Paging Request to this UE (see TS 23.502 [3] clause 4.2.3.3), if a UE is not prevented from responding e.g. due to MICO mode or Mobility Restrictions. The AMF shall enter CM-CONNECTED state for the UE whenever an N2 connection is established for this UE between the AN and the AMF. The reception of initial N2 message (e.g., N2 INITIAL UE MESSAGE) initiates the transition of AMF from CM-IDLE to CM-CONNECTED state. The UE and the AMF may optimize the power efficiency and signalling efficiency of the UE when in CM-IDLE state e.g. by activating MICO mode (see clause 5.4.1.3).
5.3.3.2.3 CM-CONNECTED state
A UE in CM-CONNECTED state has a NAS signalling connection with the AMF over N1. A NAS signalling connection uses an RRC Connection between the UE and the NG-RAN and an NGAP UE association between the AN and the AMF for 3GPP access. A UE can be in CM-CONNECTED state with an NGAP UE association that is not bound to any TNLA between the AN and the AMF. See clause 5.21.1.2 for details on the state of NGAP UE association for an UE in CM-CONNECTED state. Upon completion of a NAS signalling procedure, the AMF may decide to release the NAS signalling connection with the UE. In the CM-CONNECTED state, the UE shall:
enter CM-IDLE state whenever the AN signalling connection is released (entering RRC Idle state over 3GPP access or when the release of the UE-N3IWF connectivity over untrusted non-3GPP access or the UE-TNGF connectivity over trusted non-3GPP access is detected by the UE), see TS 38.331 [28] for 3GPP access. When the UE CM state in the AMF is CM-CONNECTED, the AMF shall:enter CM-IDLE state for the UE whenever the logical NGAP signalling connection and the N3 user plane connection for this UE are released upon completion of the AN Release procedure as specified in TS 23.502 [3]. The AMF may keep a UE CM state in the AMF in CM-CONNECTED state until the UE de-registers from the core network. A UE in CM-CONNECTED state can be in RRC Inactive state, see TS 38.300 [27]. When the UE is in RRC Inactive state the following applies:UE reachability is managed by the RAN, with assistance information from core network;UE paging is managed by the RAN.UE monitors for paging with UE’s CN (5G S-TMSI) and RAN identifier.
5.3.3.2.4 5GS Connection Management State models
Figure 5.3.3.2.4-1: CM state transition in UE
Figure 5.3.3.2.4-2: CM state transition in AMF When a UE enters CM-IDLE state, the UP connection of the PDU Sessions that were active on this access are deactivated. NOTE: The activation of UP connection of PDU Sessions is documented in clause 5.6.8.
5.3.3.2.5 CM-CONNECTED with RRC Inactive state
RRC Inactive state applies to NG-RAN. UE support for RRC Inactive state is defined in TS 38.306 [69] for NR and TS 36.306 [70] for E-UTRA connected to 5GC. RRC Inactive is not supported by NB-IoT connected to 5GC. The AMF shall provide assistance information to the NG-RAN, to assist the NG-RAN’s decision whether the UE can be sent to RRC Inactive state except due to some exceptional cases such as:
https://blog.csdn.net/u010178611/article/details/81633658
展开全文
YK14770015714 2021-07-12 16:47:55
• ## Event representations with tensor-based compositions笔记 深度学习 人工智能

weixin_42629959 2021-06-18 10:31:37
• ## vimplus YouCompleteMe unavailable: requires Vim compiled with Python (3.6.0+) support. vim python

carol2358 2021-09-26 14:48:13
• weixin_33983809 2021-01-18 19:41:22
• ## Linux RabbitMQ - CLI tool fails to authenticate with the server kafka

a1368783069 2021-03-28 02:11:05
• weixin_39798626 2021-06-08 10:29:41
• it_xiangqiang 2021-03-18 09:48:22
• weixin_42326661 2021-01-19 03:15:03
• weixin_39557576 2021-04-23 10:55:23
• qq_47805483 2021-01-19 11:31:56
• ## 论文学习笔记 Diogenes: Lightweight Scalable RSA Modulus Generation with a Dishonest Majority 算法 线性代数 抽象代数

WINCJS 2021-03-26 11:30:42
• weixin_30416973 2021-01-27 17:43:16
• weixin_34236672 2021-02-27 19:37:42
• ## 元学习：Meta Learning on a Sequence of Imbalanced Domains with Difficulty Awareness（二） 人工智能 数据挖掘

m0_51330713 2021-11-07 11:48:18
• ## [POJ2248] Addition Chains 迭代加深搜索 java迭代加深搜索

weixin_39607937 2021-04-18 07:09:18
• ## 23. Introduction to Data Visualization with ggplot2 datacamp r语言 ggplot2

agoldminer 2021-07-12 17:12:26
• ## 异常检测阅读笔记《Learning Normal Dynamics in Videos with Meta Prototype Network》，元学习，内存网络 深度学习 自然语言处理 神经网络

qq_45496282 2021-09-13 09:03:19
• weixin_44178736 2021-03-13 19:12:05
• ## leetcode 598. Range Addition II（python） leetcode

wang7075202 2020-12-18 14:13:00
• weixin_35665083 2021-06-30 03:41:35
• ## 软件工程与应用第四篇报告 1024程序员节

qq_45817834 2021-10-24 22:46:36
• ## 一个很有意思的问题,数据库在with下,数据库不支持除法 数据库 sql

weixin_47935594 2021-12-14 22:36:36
• Lionel_Coder 2021-08-17 22:57:44
• weixin_43593330 2020-12-28 19:56:00
• fuli911 2021-04-16 14:30:18
• qq_38932073 2021-04-11 09:43:40
• ## [LeetCode] Minimum Total Space Wasted With K Resizing Operations c++

sinat_24796205 2021-08-08 16:01:09

...