9.25 吉比特笔试
1、转换为10进制比较就好; 100%;
#include <bits/stdc++.h> using namespace std; int main(){ long len1, k1, len2, k2; cin >> len1 >> k1 >> len2 >> k2; string num_1; cin >> num_1; string num_2; cin >> num_2; long long num1=0, num2=0; for(long i=num_1.size()-1; i>= 0; i--){ num1 += (num_1[i] - '0') * pow(k1, num_1.size()-1-i); } for(long i=num_2.size()-1; i>= 0; i--){ num2 += (num_2[i] - '0') * pow(k2, num_2.size()-1-i); } if(num1< num2){ cout << "<"; }else if(num1> num2){ cout << ">"; }else{ cout << "="; } return 0; }2、垃圾题目,写了一个最短路径算法,但是不知道他的测试用例怎么来的; 0%;
3、网上有原题;//https://www.nowcoder.com/users/938063436 //这位老哥的代码,直接用bfs能够过 #include <bits/stdc++.h> using namespace std; int main(){ int N,M; cin>>N>>M; vector<int> result(N,-1); unordered_map<int, vector<pair<int,int>>> adj; //{node, {adjacent_node, weight}} int v1,v2,w; for(int i=0;i<M;i++){ cin>>v1>>v2>>w; adj[v1-1].push_back({v2-1,w}); adj[v2-1].push_back({v1-1,w}); } result[0]=0; queue<pair<int,int>> q;//{index, cost} q.push({0,0}); while(!q.empty()){ int index=q.front().first; int cost=q.front().second; q.pop(); if(result[index]<cost) continue; //find adjacent two step index for(auto &p1:adj[index]){ for(auto &p2:adj[p1.first]){ int temp_cost=(p1.second+p2.second)*(p1.second+p2.second)+cost; if(result[p2.first]==-1 || result[p2.first]>temp_cost){ result[p2.first]=temp_cost; q.push({p2.first, temp_cost}); } } } } for(auto c:result){ if(c==-1) cout<<"no"<<" "; else cout<<c<<" "; } cout<<endl; return 0; }
#include <iostream> #include <sstream> #include <vector> #include <string> #include <algorithm> #include <set> #include <map> #include <queue> #include <cstdio> #include <cstdlib> #include <cstring> #include <cctype> #include <cmath> using namespace std; int data[50001]; int ff[50001], bb[50001]; int n; int solve() { int s = 0; //ff[i]表示范围0->i的数据构成的最大子段值,可以不取,值永远非负 for (int i = 0; i < n; ++i) { if (i) ff[i] = ff[i - 1]; else ff[i] = 0; if (s < 0) s = 0; //s表示从0->i,以i结尾的最大子段值 s += data[i]; ff[i] = max(ff[i], s); //取以i结尾的最大字段值与历史上最大的最大子段值的最大值 } s = 0; //这个步骤和上面类似,只不过是从右往左处理,bb[i]表示从n - 1 ~ i构成的最大字段值 for (int i = n - 1; i >= 0; --i) { if (i < n - 1) bb[i] = bb[i + 1]; else bb[i] = 0; if (s < 0) s = 0; s += data[i]; bb[i] = max(bb[i], s); } //遍历断开的位置,取最大值 int ans = 0; for (int i = 0; i < n - 1; ++i) ans = max(ans, ff[i] + bb[i + 1]); return ans; } int main() { int T; scanf("%d", &T); while (T--) { scanf("%d", &n); int sum = 0, cnt = 0; for (int i = 0; i < n; ++i) { scanf("%d", &data[i]); sum += data[i]; if (data[i] > 0) cnt++; } //由于solve不能处理正数元素小于等于2的情况,因此需要单独处理 if (cnt <= 2) { sort(data, data + n, greater <int>()); printf("%d/n", data[0] + data[1]); continue; } int s1 = solve(); //正的最大子段 for (int i = 0; i < n; ++i) //求反数的最大子段,相当与求最小子段 data[i] = -data[i]; int s2 = sum + solve(); //去除最小子段 printf("%d/n", max(s1, s2)); } return 0; }改一下输入输出就好