精华内容
下载资源
问答
  • Quantity addition with zero

    2021-01-06 20:10:57
    <div><p>Adding a <code>Quantity</code> with 0 (or an array of zeros) removes the unit: <pre><code> >>> (5. * u.electron) + 0. 5 </code></pre> <p>The result is still a <code>Quantity, but...
  • s a quick way to implement a netflow dashboard in LibreNMS with a Plugins page : - Use ELK (Elasticsearch, Logstash, Kibana) to collect netflow traffic - <em>we use the netflow plugin in Logstash</em>...
  • <div><p>When adding two arrays with a set of labelled legs that is (up to permutation) identical, the result of array addition can be counter-intuitive since it uses the order of legs instead of their...
  • m unable to run a non-exact GP model with white noise kernel addition. Specifically, I tried the Kronecker classification and regression examples, along with the additive classification example, ...
  • <div><p>While this is ok: <pre><code> rascal>2.5 + {}; set[real]: {2.5} ...): addition not supported on rat and set[void] </code></pre>该提问来源于开源项目:usethesource/rascal</p></div>
  • <div><p>ECC is less compute intensive which helps in constrained devices. <p>https://www.leaderssl.com/articles/345-what-is-ecc-and-why-you-should-use-it</p><p>该提问来源于...bytebeamio/rumqtt</p></div>
  • And thanks for fixing the bug with Firefox hello, much appreciated. <p>Many Gnome Shell users use htitle with firefox as it removes the title bar if the window is maximised. <p>But when you use ...
  • <p>My Config: connection in xDrip to nightscout via API, also in AAPS, and in addition in AAPS xDrip as the source for Glucose-values.</p><p>该提问来源于开源项目:NightscoutFoundation/xDrip</p>...
  • <div><p>Just trying to create a new url with pagination like so <pre><code> href="/list?page=#(currentPage - 1)&size=#(pageSize)" </code></pre> <p>My Struct context declares ...
  • License addition

    2020-12-05 09:37:13
    <div><p>Proposing a license addition with a permissive MIT license or really any of your choosing. Many organizations require a license file to be present in a repo to consider it available for use....
  • <div><p>I basically tried to copy and paste the extended component provided above, but the map would not appear until I defined the style parameters. I wasted a good amount of time trying to render ...
  • <div><p>Update the README to include Sender information example merged in #41 . We should also bump the version.</p><p>该提问来源于开源项目:tshaddix/webext-redux</p></div>
  • 最近在学习Algorithms 4th, 做个... Binary search with only addition and subtraction. [Mihai Patrascu] Write a program that, given an array of N distinct int values in ascending order, determines whether a

    最近在学习Algorithms 4th, 做个记录

    题目

    Binary search with only addition and subtraction. [Mihai Patrascu] Write a program that, given an array of N distinct int values in ascending order, determines whether a given integer is in the array. You may use only additions and subtractions and a constant amount of extra memory. The running time of your program should be proportional to log N in the worst case.
    仅用加减实现的二分查找。编写一个程序给定一个含有N个不同int值并按照升序排序的数组,判断是否有给定的整数,只能用加法和减法以及额外的内存,程序运行时间在最坏情况下应该和logN成正比

    解决方法

    package day1;
    
    import edu.princeton.cs.algs4.*;
    
    import java.util.Arrays;
    import java.util.HashSet;
    
    public class Mihai_Patrascu {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            int[] arr = getArr(20000);
            StdOut.println();
            Arrays.sort(arr); // 排序
            for (int i :arr){
                StdOut.print(i+" ");
            }
    //      fbnq(10, 5, 2);
            int index = max(arr, 0, arr.length, 10);
            StdOut.println("answer: "+index);
        }
        /**
         * 
         * @param arr 数组
         * @param lo 起始下标
         * @param hi 最终下标
         * @param goal 查找的参数
         * @return
         */
        public static int  max(int[] arr, int lo, int hi, int goal) {
            if (lo > hi) return -1;
            // init 
            if (hi - lo <= 2) {
                if (arr[lo] == goal) return lo;
                if (arr[hi] == goal) return hi;
                else {
                    return -1;
                }
            }else {
    
                int k3 = 0;
                int i = 3;
                while (k3 < hi) {
                    i++;
                    k3 = fbnq(i, lo,  1) - lo;
                    StdOut.print(k3 + " ");
                }
                StdOut.println();
    
                int k2 = fbnq(i - 1, 0, 1) + lo;
                if (arr[k2] > goal) return max(arr, lo, k2 - 1, goal);
                if (arr[k2] < goal) return max(arr, k2 + 1, hi, goal);
                else return k2;
            }
    
    
        }
    
        // 斐波那契数列
        /**
         * 
         * @param n 下标
         * @param first 第一个数
         * @param second 第二个数
         * @return n小标下的数字
         */
        public static int fbnq(int n,int first, int second) {
            int a = first;
            int b = second;
            if (n < 3) return 1;
            else {
                int i = 3;
                while (i <= n) {
                    int temp ;
                    temp = a;
                    a = b;
                    b = temp + a;
                    i++;
    //              StdOut.print(b+" ");
                }
                return b;
            }
        }
    
        // 创建不重复的数组
        public static int[] getArr(int arrSize) {
            HashSet< Integer> set = new HashSet<>();
            int[] arr = new int[arrSize];
            for (int i = 0; i<arrSize; i++){
                int a = StdRandom.uniform(arrSize * 2); // 可能会再创建的时候多费一点时间, 但是有利于查找到对应的数字
                int count = set.size();
                set.add(a);
                if (count < set.size()) {
                    arr[i] = a;
                }else {
                    i--;
                }
            }
            return arr;
        }
    
    }
    
    

    最后

    stakoverflow上有关于斐波那契search和binary search谁快的问题,答者扯到的硬件方面不是很了解
    附上链接
    也没怎么精简校验,有错误可以联系我,会及时纠正

    展开全文
  • <div><p>After installing this package, my Selection Addition functionality no longer works. In particular the <code>CMD</code> + <code>Left Mouse Click</code>. I looked through your default ...
  • <p>However, once I add 1000 documents concurrently and all callbacks are fired, I retrieve only about 330 of them with search method. Is this expected?</p><p>该提问来源于开源项目:fergiemcdowall...
  • <p>I propose a addition to ISystem with Added/Removed methods that deal with Entities being added/removed from the world (or activated/deactivated). <p>This would be useful for dealing with ...
  • with my libre sensor since a few days after having used Glimp for a long time. My mobile is a Samsung s5mini. <p>99% by scanning over NFC instead of using BluCon. <p>Now I miss the values and the ...
  • <div><p>This PR is to add the AD Kibana IntegTest addition to build workflows WITH Security with #333. Also: https://github.com/opendistro-for-elasticsearch/opendistro-infra/issues/232</p> <h3>Test ...
  • t get rebase to fix failed CLA check in #199, so I duplicated branch and created a new PR with the exact same changes. </li><li>I will link all change requests here. </li></ul> <p>Changes to original ...
  • <div><p>… service - as per ...774149#177 <p>rename usbmount.rules to 90-usbmount.rules updated changelog</p><p>该提问来源于开源项目:rbrito/usbmount</p></div>
  • <div><p>While I was messing around with the MSAFluid demo, I noticed <pre><code> gl2.glBegin(gl2.GL_QUADS) . . . gl2.glEnd() </code></pre> <p>I don't know that it's even possible to this...
  • We should have the same behavior for team edition: mark a transaction as executed even in case it fails and signal a failing transaction with an event. This prevents that transactions, which might ...
  • 题目:Binary search with only addition and subtraction. [Mihai Patrascu] Write a program that, given an array of N distinct int values in ascending order, determines whether a given integer is ...
    题目:Binary search with only addition and subtraction.
    [Mihai Patrascu] Write a program that, given an array of
    N distinct
    int 
    values in ascending order, determines whether a given integer is in the array. You may use only additions and subtractions

    and a constant amount of extra memory. The running time of your program should be proportional to log N in the worst case


    算法:

    package com.frozenxia.algorithm.basic;
    
    public class FibonacciSearch {
    	public int min(int a, int b) {
    		return a < b ? a : b;
    	}
    
    	public int search(int[] arr, int x, int n) {
    		/* Initialize fibonacci numbers */
    		int fibMMm2 = 0; // (m-2)'th Fibonacci No.
    		int fibMMm1 = 1; // (m-1)'th Fibonacci No.
    		int fibM = fibMMm2 + fibMMm1; // m'th Fibonacci
    
    		/*
    		 * fibM is going to store the smallest Fibonacci Number greater than or
    		 * equal to n
    		 */
    		while (fibM < n) {
    			fibMMm2 = fibMMm1;
    			fibMMm1 = fibM;
    			fibM = fibMMm2 + fibMMm1;
    		}
    
    		// Marks the eliminated range from front
    		int offset = -1;
    
    		/*
    		 * while there are elements to be inspected. Note that we compare
    		 * arr[fibMm2] with x. When fibM becomes 1, fibMm2 becomes 0
    		 */
    		while (fibM > 1) {
    			// Check if fibMm2 is a valid location
    			int i = min(offset + fibMMm2, n - 1);
    
    			/*
    			 * If x is greater than the value at index fibMm2, cut the subarray
    			 * array from offset to i
    			 */
    			if (arr[i] < x) {
    				fibM = fibMMm1;
    				fibMMm1 = fibMMm2;
    				fibMMm2 = fibM - fibMMm1;
    				offset = i;
    			}
    
    			/*
    			 * If x is greater than the value at index fibMm2, cut the subarray
    			 * after i+1
    			 */
    			else if (arr[i] > x) {
    				fibM = fibMMm2;
    				fibMMm1 = fibMMm1 - fibMMm2;
    				fibMMm2 = fibM - fibMMm1;
    			}
    
    			/* element found. return index */
    			else
    				return i;
    		}
    
    		/* comparing the last element with x */
    		if (fibMMm1 != 0 && arr[offset + 1] == x)
    			return offset + 1;
    
    		/* element not found. return -1 */
    		return -1;
    	}
    
    	int fbsearch(int[] arry, int target) {
    		int fm1 = 1;
    		int fm2 = 0;
    		int fm0 = fm1 + fm2;
    		while (fm0 < arry.length) {
    			fm2 = fm1;
    			fm1 = fm0;
    			fm0 = fm1 + fm2;
    		}
    		int offset = -1;
    		while (fm1 > 0) {
    			int mid = min((offset + fm1), arry.length - 1);
    			if (arry[mid] == target)
    				return mid;
    			else if (arry[mid] < target) {
    				fm0 = fm2;
    				fm1 = fm1 - fm2;
    				fm2 = fm2 - fm1;
    				offset = mid;
    			} else {
    				fm0 = fm1;
    				fm1 = fm2;
    				fm2 = fm0 - fm1;
    			}
    		}
    		return -1;
    	}
    
    	public static void main(String[] args) {
    		int arry[] = new int[100];
    		for (int i = 0; i < 100; i++) {
    			arry[i] = i + 8;
    		}
    		FibonacciSearch fs = new FibonacciSearch();
    		for (int i : arry) {
    			// System.out.println(fs.search(arry, i));
    			// System.out.println(fs.search(arry, i, arry.length));
    			System.out.println(fs.fbsearch(arry, i));
    		}
    		// System.out.println(fs.fbsearch(arry, -1887));
    	}
    }
    


    Reference:

    http://www.geeksforgeeks.org/fibonacci-search/

    展开全文
  • Doing float addition with small dts and long simulations makes rounding errors pretty much a guarantee. Instead, in this PR we just multiply the number of steps (int addition, safe, which we already ...
  • <div><p>If item has datatime type fields - clone item has error</p><p>该提问来源于开源项目:bolt/bolt</p></div>
  • With this new feature filter users will be able to target specific users, groups, and a user wide percentage when rolling out new features. <p>The readme contains an in-depth overview of targeting ...
  • <div><p>该提问来源于开源项目:xbianonpi/xbian</p></div>
  • This is because with the addition of "App Resource Library", when you long press to delete an app, the original menu text is adjusted from "Remove from Home Screen" to "Move to App Resource Library" ...

    This is because with the addition of "App Resource Library", when you long press to delete an app, the original menu text is adjusted from "Remove from Home Screen" to "Move to App Resource Library" and "Delete App". In other words, if you use an app icon that is low in frequency or that affects the look and feel, you can put it in the resource library instead of displaying it on the main screen.

    展开全文
  • Addition

    2014-08-20 11:41:19
    Six years ago, a robot, Bob, with infant's intelligence has been invented by an evil scientist, Alice. Now the robot is six years old and studies in primary school. Addition is the first o

    Problem

    Six years ago, a robot, Bob, with infant's intelligence has been invented by an evil scientist, Alice.

    Now the robot is six years old and studies in primary school. Addition is the first operation he learned in math. Due to his strong reasoning ability, he could now conclude a+b=12 from a=2 and b=10.

    Alice wanted to test Bob's addition skills. Some equations were given to Bob in form of a=2, b=10, c=4, and Bob has to find out the answers of questions like a+b, a+c, etc.

    Alice checked Bob's answers one by one in the test papers, and no mistake has been found so far, but Alice lost the given equations after a cup of coffee poured on them. However she has some of Bob's correct answers, e.g. a+b=12, a+c=6, c+d=5. She wants to continue with the checkable equations, e.g. b+d=11 could be concluded by a+b=12, a+c=6, c+d=5, and thus the question b+d is checkable.

    To prevent the artificial intelligence technology from being under the control of Alice, you disguised yourself as her assistant. Now Alice wants you to figure out which of the rest of questions are checkable and their answers.

    Input

    The first line of the input gives the number of test cases, TT test cases follow.

    The first line of each test case contains a single integer N: the number of correctly answered questions. Each of the next N lines contain one correctly answered question in the form "x+y=z", where x and y are names of variables and z is a decimal integer.

    The next line contains a single integer Q: the number of remaining questions. Each of the next Q lines contain one question in the form "x+y", where x and y are names of variables.

    Output

    For each test case, the first line of output contains "Case #x:", where x is the test case number (starting from 1). For each question in the input that was checkable, output a single line with the answer in the form "x+y=z", where x and y are names of variables andz is a decimal integer. Questions should be listed in the same order as they were given in the input. Please do NOT ignore duplicated questions, since Alice would fire you if you pointed any mistake of hers.

    Limits

    Names of variables are strings of lowercase English letters. Each name contains at most 10 characters.

    -200000 ≤ z ≤ 200000

    There is no contradiction in the answered questions.

    Small dataset

    T ≤ 10

    N ≤ 10

    Q ≤ 10

    Large dataset

    T ≤ 3

    N ≤ 5000

    Q ≤ 5000

    Sample


    Input 
     

    Output 
     
    2
    2
    apple+banana=10
    coconut+coconut=12
    5
    apple+banana
    apple+banana
    apple+apple
    banana+apple
    peach+apple
    3
    a+b=3
    b+c=3
    c+d=3
    4
    a+c
    a+d
    b+c
    b+d
    
    
    Case #1:
    apple+banana=10
    apple+banana=10
    banana+apple=10
    Case #2:
    a+d=3
    b+c=3
    

    将变量抽象为图顶点,等式抽象为图的边,看能否有奇数条边的通路即可。使用BFS搜索。

    #include <iostream>
    #include <fstream>
    #include <vector>
    #include <string>
    #include <unordered_map>
    #include <queue>
    #include <sstream>
    
    using namespace std;
    
    struct GEdge
    {
        int To;         // the other end
        int Value;      // value of the edge
        GEdge(int to, int val) : To(to), Value(val) {}
    };
    
    typedef vector<GEdge> EdgeArray;
    vector<EdgeArray> g_Graph;              // all edges from node i
    unordered_map<string, int> g_Nodes;     // all nodes
    int g_NodeCount;                        // used to generate the node index
    
    void add_edge(int node1, int node2, int val)
    {
        // undirected graph
        g_Graph[node1].push_back(GEdge(node2, val));
        g_Graph[node2].push_back(GEdge(node1, val));
    }
    
    int get_node(const string &name) // fetch or create a node
    {
        if (g_Nodes.count(name) > 0)
            return g_Nodes[name];
        return (g_Nodes[name] = g_NodeCount++);
    }
    
    bool bfs_search_path(int &val, int from, int to)
    {
        vector<bool> visited(g_NodeCount, false);
        queue<GEdge> Q;
        for (auto edge : g_Graph[from])
            Q.push(edge);
        while (!Q.empty())
        {
            GEdge cur = Q.front();
            Q.pop();
            int node = cur.To;
            if (node == to)
            {
                val = cur.Value;
                return true;
            }
            for (auto e : g_Graph[node])
            {
                for (auto ee : g_Graph[e.To]) // two loops to find odd edges
                {
                    if (visited[ee.To])
                        continue;
                    visited[ee.To] = true;
                    Q.push(GEdge(ee.To, cur.Value - e.Value + ee.Value));
                }
            }
        }
        return false;
    }
    
    void work_single(istream &input, ostream &output)
    {
        int N;
        input >> N;
    
        // clear graph
        g_Graph.clear();
        g_Nodes.clear();
        g_NodeCount = 0;
        g_Graph.resize(N * 2);
    
        // read and build graph
        for (int i = 0; i < N; i++)
        {
            string line;
            input >> line;
            // find +,= position
            size_t j;
            for (j = 0; j < line.length(); j++)
            {
                if (line[j] == '+' || line[j] == '=')
                    line[j] = ' ';
            }
            string name1, name2;
            int val;
            istringstream line_stream(line);
            line_stream >> name1 >> name2 >> val;
            // add edge
            int node1 = get_node(name1);
            int node2 = get_node(name2);
            add_edge(node1, node2, val);
        }
        
        int Q;
        input >> Q;
        for (int i = 0; i < Q; i++)
        {
            string line;
            input >> line;
            // find +
            size_t j;
            for (j = 0; j < line.length(); j++)
            {
                if (line[j] == '+')
                    break;
            }
            string name1 = line.substr(0, j);
            string name2 = line.substr(j + 1, line.length() - j - 1);
            if (g_Nodes.count(name1) == 0 || g_Nodes.count(name2) == 0)
                continue;
            int node1 = get_node(name1);
            int node2 = get_node(name2);
            int val;
            if (bfs_search_path(val, node1, node2))
                output << line << "=" << val << endl;
        }
    }
    
    void work(istream &input, ostream &output)
    {
        int case_count;
        input >> case_count;
        for (int i = 0; i < case_count; i++)
        {
            output << "Case #" << i + 1 << ":" << endl;
            work_single(input, output);
        }
    }
    
    int main(int argc, char *argv[])
    {
        bool use_stdio = false;
        if (use_stdio)
            work(cin, cout);
        else
        {
            ifstream input("C-large-practice.in");
            ofstream output("C-large-practice.out");
            work(input, output);
        }
        return 0;
    }



    展开全文
  • <div><p>Hi guys! this is my first contribution to this project and I wanted to ensure that this code is correct in terms of the contributions guideline. So a little hand holding would be appreciated. ...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 34,317
精华内容 13,726
关键字:

additionwith