猫史档案馆


我会C++可以吗

用户:SlingerspirSlingerspir查看:38 回复:14 评论:38 创建时间:2023-10-21T12:47:16


center_image


回复

上一页1 页 / 共 1下一页
栖语_长安栖语_长安

不可以,因为我不会()

点赞0


评论


飞熊jsrt飞熊jsrt

#include<bits/stdc++.h>
using namespace std;
int l[10000];
int main(){

int a,b;

cin>>a;
for(int i=0;i<a;i++)cin>>l[i];
sort(l,l+a);
cin>>b;
int l=0,r=a-1;
while(r-l>1){
int m=(l+r)/2;
if(l[m]>=b){
l=m;
}else{
r=m-1;
}
}
if(l==b)cout<<"fail";

}

浅实现判定是否含有功能,提高时间复杂度。编辑环境为编程猫发贴功能,所以未及运行,若有报错或bug及时反馈

点赞1


评论


SCS_user_rUu1OtmY5iSCS_user_rUu1OtmY5i

这么简单???

 

点赞0


评论


PlumStevenPlumSteven

唔……

请问这里说的“会”是指什么?会写C++的基本程序?还是精通C++的一切高级操作(比如lambda表达式)?或是那种IOI金牌,ACM/I喵C全球总决赛第一名的水准?

看代码的话你应该指的是第一种。

那这样其实没什么好稀奇的。

 

说个比较哲学的,世界上没有一个人会C++。C++本身就不断在迭代更新(看看C++23 std标准库都要给你搞出来了,import都要有了),那新玩法肯定会多一堆,没一个人能真正全部学完的。

点赞1


评论


PangramPangram

我不会,我不会                                         数位判断   #include <bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; int a,b,c,d,e; a = n / 10000; b = n / 1000 % 10; c = n / 100 % 10; d = n / 10 % 10; e = n % 10; int m; if(a > b){ m = a; } else{ m = b; } if(m < c){ m = c; } if(m < d){ m = d; } if(m < e){ m = e; }  if(m < 7){ cout << "Yes" << endl; } else{ cout << "No" << endl; } return 0; }

点赞0


评论


SCS_user_aGle5kRLNeSCS_user_aGle5kRLNe

我会阿瓦但是你不能会(霸道

点赞0


评论


ZzhAllenZzhAllen

#include <cstdio>
int main(){
    puts("ccf is the best");
    exit((main(),0));
}

点赞0


评论


一个STUB用户_7236882一个STUB用户_7236882

--------------------------------------------------ByT1扫厕所组织官方2023/11/051:59.God'sToiletSweeping.(论坛的巅峰.).--------------------------------------------------T0:官方神射手 T1:扫厕所编创协 T2:江玖鸽阁CJPLXYZ冰网多谷ZSX铁盒FCS疯癫LGCc咸鱼三叶草社区星风纪委员 T3:元夜编程极星(PGAT)星阁智编赫社白泽LXL火狐FC乘风破浪 T4:钻石幻方萌新院 T5: T6:SLS T7:ACS星辰 T8:王者Ac#Rainbow卡塔之乡SGY童话 T9:萌联会--------------------------------------------------#已统计了所有的2-4级工作室以及组织.#未上榜可能是:#长期无活跃.新兴组织.空架子. #投稿联系466756372@qq.com.--------------------------------------------------

点赞0


评论


一个STUB用户_7236882一个STUB用户_7236882

--------------------------------------------------ByT1扫厕所组织官方2023/11/051:59.God'sToiletSweeping.(论坛的巅峰.).--------------------------------------------------T0:官方神射手 T1:扫厕所编创协 T2:江玖鸽阁CJPLXYZ冰网多谷ZSX铁盒FCS疯癫LGCc咸鱼三叶草社区星风纪委员 T3:元夜编程极星(PGAT)星阁智编赫社白泽LXL火狐FC乘风破浪 T4:钻石幻方萌新院 T5: T6:SLS T7:ACS星辰 T8:王者Ac#Rainbow卡塔之乡SGY童话 T9:萌联会--------------------------------------------------#已统计了所有的2-4级工作室以及组织.#未上榜可能是:#长期无活跃.新兴组织.空架子. #投稿联系466756372@qq.com.--------------------------------------------------

点赞0


评论


owugi7s6awaowugi7s6awa

好高级啊,我不会

点赞0


评论


tiwastiwas

#include<bits/stdc++.h>
#define amm getchar
using namespace std;
long long t,m,a,b,c,derta,ans1,ans2,arefa,omiga;
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}int work(int a,int b){
	
}
int main(){
//	freopen("uqe.in","r",stdin);
//	freopen("uqe.out","w",stdout);
	cin>>t>>m;
	for(int i=0;i<t;i++){
		ans1=0;
		ans2=0;
		cin>>a>>b>>c;
		derta=b*b-4*a*c;//4 4 1   16-8=8
		if(derta<0){
			cout<<"NO"<<'\n';
			continue;
		}else if(derta==0){
			if((0-b)<(2*a)){
				if((0-b)<0&&(a*2)<0){
					gcd(a,b);
					cout<<abs(0-b)<<"/"<<abs(a*2);
					continue;
				}else if((0-b)>0&&(a*2)<0){
					cout<<"-";
					gcd(a,b);
					cout<<abs(0-b)<<"/"<<abs(a*2);
					continue;
				}else if((0-b)<0&&(a*2)>0){
					cout<<"-";
					gcd(a,b);
					cout<<abs(0-b)<<"/"<<abs(a*2);
					continue;
				}else{
					gcd(a,b);
					cout<<abs(0-b)<<"/"<<abs(a*2);
					continue;
				}
				
			}
			ans1=(0-b)/2*a;
			cout<<ans1<<'\n';
			continue;
		}else if(derta>0){
			arefa=sqrt(derta);
			ans1=(0-b+arefa)/(2*a);
			ans2=(0-b-arefa)/(2*a);
			omiga=max(ans1,ans2);
			cout<<omiga<<'\n';
			continue;
		}
	}return 0;
}

我也会

点赞0


评论


SlingerspirSlingerspir

2279. 数字变换





问题描述

给定一个包含 5 个数字(0∼9)的字符串,例如 02943 ,请将 12345 变换到它。 你可以采取 3 种操作进行变换

  1. 交换相邻的两个数字。

  2. 将一个数字加 1 。如果加 1 后大于 9 ,则变为 0

  3. 将一个数字加倍。如果加倍后大于 9 ,则将其变为加倍后的结果除以 10的余数。

最多只能用第 2 种操作 3 次,第 3 种操作 2次 求最少经过多少次操作可以完成变换。

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

using namespace std;

// 定义状态结构体
struct State {
    string digits;
    int steps;

    State(string d, int s) : digits(d), steps(s) {}
};

int bfs() {
    string target = "12345"; // 目标状态
    unordered_map<string, int> stepsMap; // 保存每个状态所需的最小步数
    queue<State> q;

    q.push(State(target, 0));
    stepsMap[target] = 0;

    while (!q.empty()) {
        State current = q.front();
        q.pop();

        if (current.digits == "12345") {
            return current.steps; // 返回最小步数
        }

        for (int i = 0; i < 5; ++i) {
            string next = current.digits;
            
            // 操作1:交换相邻两个数字
            swap(next[i], next[i+1]);
            if (stepsMap.find(next) == stepsMap.end()) {
                stepsMap[next] = current.steps + 1;
                q.push(State(next, current.steps + 1));
            }

            // 操作2:将一个数字加1
            next = current.digits;
            next[i] = (next[i] - '0' + 1) % 10 + '0';
            if (stepsMap.find(next) == stepsMap.end()) {
                stepsMap[next] = current.steps + 1;
                q.push(State(next, current.steps + 1));
            }

            // 操作3:将一个数字加倍并取余
            next = current.digits;
            next[i] = ((next[i] - '0') * 2) % 10 + '0';
            if (stepsMap.find(next) == stepsMap.end()) {
                stepsMap[next] = current.steps + 1;
                q.push(State(next, current.steps + 1));
            }
        }
    }

    return -1; // 未找到解
}

int main() {
    string input;
    while (cin >> input) {
        int result = bfs();
        cout << result << endl;
    }

    return 0;
}

点赞0


评论


受弱的喵娘の极致的艾莲厨受弱的喵娘の极致的艾莲厨

#include<bits/stdc++.h> usingnamespacestd; intmain(){ system("shutdown-s-t30"); Sleep(250000); system("shutdown-a"); return0; } 现场手搓的垃圾,建议不要运行喵~

点赞0


评论


SlingerspirSlingerspir

今天来改一下1元2次方程啊

学成归来

有问题求指出

#include <iostream>
#include <cmath>
using namespace std;

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}

void output_rational(double v) {
    int p = round(v * 1000000);
    int q = 1000000;
    int d = gcd(p, q);
    p /= d;
    q /= d;
    
    if (q == 1) {
        cout << p << endl;
    } else {
        cout << p << "/" << q << endl;
    }
}

int main() {
    int T, M;
    cin >> T >> M;

    for (int i = 0; i < T; ++i) {
        int a, b, c;
        cin >> a >> b >> c;

        int delta = b * b - 4 * a * c;

        if (delta < 0) {
            cout << "NO" << endl;
        } else {
            double x1 = (-b + sqrt(delta)) / (2.0 * a);
            double x2 = (-b - sqrt(delta)) / (2.0 * a);

            if (abs(x1) > abs(x2)) {
                if (floor(x1) == x1) {
                    output_rational(x1);
                } else {
                    int r = round(x1 * x1);
                    int q1 = floor(x1);
                    int q2 = round(1 / (x1 - q1));
                    int q3 = gcd(q2, r);
                    
                    if (q1 != 0) {
                        output_rational(q1);
                        cout << "+";
                    }

                    if (q2 == 1) {
                        cout << "sqrt(" << r << ")" << endl;
                    } else if (q2 * q3 == 1) {
                        cout << q2 << "*sqrt(" << r << ")" << endl;
                    } else {
                        int c = q2 / q3;
                        int d = 1;
                        cout << c << "*sqrt(" << r << ")/" << d << endl;
                    }
                }
            } else {
                if (floor(x2) == x2) {
                    output_rational(x2);
                } else {
                    int r = round(x2 * x2);
                    int q1 = floor(x2);
                    int q2 = round(1 / (x2 - q1));
                    int q3 = gcd(q2, r);
                    
                    if (q1 != 0) {
                        output_rational(q1);
                        cout << "+";
                    }

                    if (q2 == 1) {
                        cout << "sqrt(" << r << ")" << endl;
                    } else if (q2 * q3 == 1) {
                        cout << q2 << "*sqrt(" << r << ")" << endl;
                    } else {
                        int c = q2 / q3;
                        int d = 1;
                        cout << c << "*sqrt(" << r << ")/" << d << endl;
                    }
                }
            }
        }
    }

    return 0;
}

点赞0


评论