头像

liuser

yxc的忠实粉丝


访客:2949

离线:1天前



liuser
1天前
#include <iostream>
#include <cstdio>

using namespace std;

const int N = 100010;

int a[N];
int q[N];

int main()
{
    int n;
    scanf("%d", &n);
    for(int i = 1; i <= n; i ++ )
        scanf("%d", &a[i]);

    int len = 1;
    for (int i = 1; i <= n; i ++ )
    {
        int l = 1, r = len;
        while (l < r)
        {
            int mid = (l+r+1)/2;
            if (q[mid] < a[i]) l = mid;
            else r = mid-1;
        }
        len = max(len, r+1);
        q[r+1] = a[i];

    }

    printf("%d", len-1);

    return 0;
}



liuser
1天前

来源: y总初级班视频课

写二分的步骤 (二分小于某个数的最大的数)

  1. 分(左右区间)的范围
  2. 写模板
  3. 设计check函数,使得我们的答案在边界位置
    4.如果写的是l=mid ,更新int mid = (l+r+1)/2;其他则不用。

下面是在 [l, r]区间内查找比a[i]小的数字中最大的数字的位置

int l = 0, r = len;
while (l < r)
{
    int mid = l + r + 1 >> 1;
    if (a[mid] < a[i]) l = mid;
    else r = mid - 1;
}


活动打卡代码 AcWing 763. 循环相克令

liuser
4天前
#include <iostream>
#include <cstring>

using namespace std;

int main()
{
    int t, a, b;
    string d[] = {"Hunter", "Bear","Gun"};//强盗  熊 枪
    string x, y;
    cin >> t;
    while (t -- )
    {
        cin >> x >> y;
        for (int i = 0; i < 3; i ++ )
        {
            if (d[i] == x) a = i;
            if (d[i] == y) b = i;
        }
        if (a == b) cout << "Tie" << endl;
        else if (b - a == 2 || a - b == 1) cout << "Player1" << endl;
        else cout << "Player2" << endl;
    }
    return 0;
}



liuser
4天前
#include <iostream>
#include <cstring>

using namespace std;

int main()
{
    int ans = 0;
    string a;
    getline(cin, a);
    for (int i = 0; a[i]; i ++ )
        if (a[i] >= '0' && a[i] <= '9')
            ans ++;

    cout << ans;
    return 0;
}


活动打卡代码 AcWing 760. 字符串长度

liuser
4天前
#include <iostream>
#include <cstring>

using namespace std;

int main()
{
    string a;
    getline(cin, a);
    cout << a.size();
    return 0;
}


问题 bug

liuser
20天前
#include <iostream>
#include <cstring>

using namespace std;

const int N = 510, INF = 1e9;

int a[N][N], f[N][N], n;

int main()
{
    cin >> n;
    for (int i = 1; i <= n; i ++ )
        for (int j = 1; j <= i; j ++ )
            cin >>a[i][j];

    for (int i = 0; i < N; i ++ )
        for (int j = 0; j <= i+1; j ++ )
            f[i][j] = 0;

    cout << n << endl;

    return 0;
}

问题

我最后打印 n 的值为零,这是为什么?



活动打卡代码 AcWing 664. 三角形

liuser
1个月前
#include <iostream>
using namespace std;

int main()
{
    double a, b, c;
    cin >> a >> b >> c;

    if (a+b > c && a+c > b &&  b+c > a)
        printf("Perimetro = %.1lf", a+b+c);
    else
        printf("Area = %.1lf", (a+b)*c/2);

    return 0;

}



活动打卡代码 AcWing 78. 左旋转字符串

liuser
1个月前
class Solution {
public:
    string leftRotateString(string str, int n) {
        return str.substr(n, str.size() - n) + str.substr(0, n);
    }
};



liuser
1个月前

题目链接 acwing 78. 左旋转字符串

我遇到了有一点过不了的问题。

错误的代码:

class Solution {
public:
    string leftRotateString(string str, int n) {
        for (int i = 0; i < n; i ++ )
            str += str[i];
        int len = str.size();
        for (int i = 0; i+n <= len; i ++ )
            str[i] = str[i+n];
        return str;
    }
};

输入
“b”
1

输出
“b
标准答案
“b”




liuser
1个月前
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* merge(ListNode* l1, ListNode* l2) {
        ListNode* head = new ListNode(-1);
        ListNode* tail = head;
        while (l1 && l2)
        {
            if (l1->val < l2->val)
            {
                tail = tail->next = l1;
                l1 = l1->next;
            }
            else
            {
                tail = tail->next = l2;
                l2 = l2->next;
            }
        }
        if (l1) tail->next = l1;
        else tail->next = l2;

        return head->next;
    }  
};