HackerRank - "Manipulative Numbers"

本文介绍了一种通过位运算找出数组中元素满足特定条件的关键位的方法。利用位运算的高效特性,该算法能够快速确定满足约束条件下存在的排列,并提供了一个具体的实现示例。

The answer by Tuxdude is perfect:

http://stackoverflow.com/questions/11161465/existence-of-a-permutation-under-constraints-interview-street-manipulative-nu

Lesson learnt: always try to dig more insightful thoughts to find hidden\subtle mechanisms.

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;


int main() 
{
    //    Get input
    int n; cin >> n;
    vector<int> in(n, 0);
    for(int i = 0; i < n; i ++)
        cin >> in[i];

    //
    int maxbit = floor(log(*std::max_element(in.begin(), in.end()))/log(2));
    int k = -1;
    for (int bitcnt = maxbit - 1; bitcnt >= 0; bitcnt --)
    {
        bool bValid = true;
        unordered_map<int, unsigned> rec;
        for(auto v : in)
        {
            int vs = v >> bitcnt;
            rec[vs] ++;
            if(rec[vs] > (n/2))
            {
                bValid = false;
                break;
            }
        }
        if(!bValid)
        {
            continue;
        }
        k = bitcnt;
        break;
    }
    cout << k << endl;
    return 0;
}

 

转载于:https://www.cnblogs.com/tonix/p/4565032.html

构造文档 由于RAG的原理是先在文档中搜索,把搜索到最接近的内容喂给大模型,让大模型根据喂给它的内容进行回答,因此需要存储文档块,便于检索。这需要对文章进行切分后存入到数据库。我们选取了来自AGENT AI: SURVEYING THE HORIZONS OF MULTIMODAL INTERACTION的部分文章段落并进行嵌入。 由于文章太长,我们先要对文章进行切分。在这里,我们使用没有任何优化的顺序切分器,将文章分成了 150 个字符一段的小文本块。 embedding_text = """ Multimodal Agent AI systems have many applications. In addition to interactive AI, grounded multimodal models could help drive content generation for bots and AI agents, and assist in productivity applications, helping to re-play, paraphrase, action prediction or synthesize 3D or 2D scenario. Fundamental advances in agent AI help contribute towards these goals and many would benefit from a greater understanding of how to model embodied and empathetic in a simulate reality or a real world. Arguably many of these applications could have positive benefits. However, this technology could also be used by bad actors. Agent AI systems that generate content can be used to manipulate or deceive people. Therefore, it is very important that this technology is developed in accordance with responsible AI guidelines. For example, explicitly communicating to users that content is generated by an AI system and providing the user with controls in order to customize such a system. It is possible the Agent AI could be used to develop new methods to detect manipulative content - partly because it is rich with hallucination performance of large foundation model - and thus help address another real world problem. For examples, 1) in health topic, ethical deployment of LLM and VLM agents, especially in sensitive domains like healthcare, is paramount. AI agents trained on biased data could potentially worsen health disparities by providing inaccurate diagnoses for underrepresented groups. Moreover, the handling of sensitive patient data by AI agents raises significant privacy and confidentiality concerns. 2) In the gaming industry, AI agents could transform the role of developers, shifting their focus from scripting non-player characters to
03-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值