代码人生
12分钟前

牛牛的构造.png

#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
const int N = 1e6 + 10;
int n,k;
int fsum[N],f[N];
int main(){
    scanf("%d %d",&n,&k);
    f[1] = 0;
    for(int i=2;i<=n;i++){
        f[i] = floor(log2(i - 1)) + 1;
    }
    fsum[1] = 0;
    for(int i=2;i<=n;i++){
        fsum[i] = fsum[i - 1] + f[i];
    }
    if(fsum[n] < k){
        puts("-1");
        return 0;
    }
    vector<int> a,b;
    for(int i=n;i>=1;i--){
        if(k >= f[i]){
            k -= f[i];
            a.push_back(i);
        }
        else{
            b.push_back(i);
        }
    }
    reverse(b.begin(),b.end());
    for(vector<int>::iterator it=a.begin();it!=a.end();it++) printf("%d ",*it);
    for(vector<int>::iterator it=b.begin();it!=b.end();it++) printf("%d ",*it);
    return 0;
}


新鲜事 原文

AcWing《蓝桥杯集训·每日一题》拼团优惠!https://www.acwing.com/activity/content/introduction/2869/group_buy/123540/


新鲜事 原文

AcWing《蓝桥杯集训·每日一题》拼团优惠!https://www.acwing.com/activity/content/introduction/2869/group_buy/123539/



/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */

 /*

 正常删除结点的操作是,找到前驱结点P之后P->next=p->next->next,但时间复杂度为O(n)

 这题需要用O(1),因此可以用删去的结点(下一个结点一定不是空结点)后面的结点来覆盖,
 并且删除下一个结点

 */
class Solution {
public:
    void deleteNode(ListNode* node) {//知道当前结点位置
        node->val=node->next->val;
        node->next=node->next->next;
    }
};


新鲜事 原文

Haruki
19分钟前
渔蓑句好真堪画,柳絮才高不道盐



Dgt-pgr
24分钟前

C++ 代码

#include <iostream>
#include <cstring>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <string>

using namespace std;
string st;
string ed;
unordered_map<string, int> dist;//操作步数
unordered_map<string, pair<char, string>> way;//路径
string res;

void chushihua()
{
    for (int i = 0; i < 8; i ++)
    {
        st += char(i + '1');
    }
    for (int i = 0; i < 8; i ++)
    {
        int x;
        cin >> x;
        ed += char(x + '0');
    }
    return;
}

string move0(string s)
{
    string k = s;
    for (int i = 0; i < 8; i ++) s[i] = k[7 - i];
    return s;
}
string move1(string s)
{
    string k;
    int cnt = 0;
    k[cnt] = s[3];
    for (int i = 0; i < 3; i ++)
    {
        k[++ cnt] = s[i];
    }
    for (int i = 5; i < 8; i ++)
    {
        k[++ cnt] = s[i];
    }
    k[++ cnt] = s[4];
    for (int i = 0; i < 8; i ++) s[i] = k[i];
    return s;
}
string move2(string s)
{
    string k;
    k[0] = s[0], k[1] = s[6], k[2] = s[1], k[3] = s[3], k[4] = s[4], k[5] = s[2], k[6] = s[5], k[7] = s[7];
    for (int i = 0; i < 8; i ++) s[i] = k[i];
    return s;
}
void bfs()
{
    if (st == ed) return;
    queue<string> q;
    q.push(st);
    dist[st] = 0;
    while (!q.empty())
    {
        string s = q.front();
        q.pop();
        string m[3];
        m[0] = move0(s);
        m[1] = move1(s);
        m[2] = move2(s);
        for (int i = 0; i < 3; i ++)
        {
            string ss = m[i];
            if (dist.count(ss) == 0)
            {
                dist[ss] = dist[s] + 1;
                way[ss] = {i + 'A', s};
                q.push(ss);
                if (ss == ed) return;
            }
        }
    }
    return;
}
int main()
{
    chushihua();

    bfs();

    cout << dist[ed] << endl;

    while (ed != st)
    {
        res += way[ed].first;
        ed = way[ed].second;
    }
    reverse(res.begin(), res.end());
    if (res.size()) cout << res << endl;

    return 0;
}



royelyl
25分钟前

C++ 代码

#include <bits/stdc++.h>

using namespace std;

const int maxn = 100000 + 5;

int prime[maxn], pNum = 0;
bool p[maxn] = {false};

void Find_Prime(int n) {
    for (int i = 2; i < n; i++) {
        if (p[i] == false) {
            prime[pNum++] = i;
            for (int j = i + i; j < n; j += i) {
                p[j] = true;
            }
        }
    }
}

int main()
{

    int n;
    while (scanf("%d", &n) != EOF) {
    Find_Prime(n);
    bool flag = false;
    for (int i = 0; i < pNum; i++) {
        string str;
        str = to_string(prime[i]);
        if (str[str.size() - 1] == '1') {
            cout << prime[i] << " ";
            flag = true;
        }
    }
    pNum = 0;
    if (flag == false) cout << "-1";
    cout << endl;
    }

}


新鲜事 原文

夕于.
28分钟前
AcWing《蓝桥杯集训·每日一题》拼团优惠!https://www.acwing.com/activity/content/introduction/2869/group_buy/123483/


新鲜事 原文

安波里欧
33分钟前
功力退步了... 一道中缀转后缀写了三小时
图片


新鲜事 原文

晓山青
42分钟前
bfs走迷宫 #include<iostream> #include<cstring> #include<queue> using namespace std; typedef pair<int,int> PII; const int N = 110; int a[N][N],d[N][N]; int n,m; int dx[] = {0,0,-1,1},dy[] = {1,-1,0,0}; queue<PII> q; void bfs() { q.push({1,1}); while(q.size()) { auto t = q.front(); q.pop(); for(int i =0;i<4;i++) { int x = t.first + dx[i],y = t.second + dy[i]; if(x>=1&&x<=n&&y>=1&&y<=m&&a[x][y]==0&&d[x][y]==-1) { d[x][y] = d[t.first][t.second]+1; q.push({x,y}); } } } } int main() { cin>>n>>m; memset(d,-1,sizeof d); d[1][1] = 0; for(int i =1;i<=n;i++) for(int j =1;j<=m;j++) cin>>a[i][j]; bfs(); cout<<d[n][m]<<endl; }