求助大佬,网易互娱的题,哪个大佬通过了,分享个思路与代码吧

做了第一题和第二题

自测都能通过

但是,一个case 0,一个case 10

我是哪里没想到啊,求指教
#网易##笔试题目#
全部评论
5~13都叫顺子
点赞 回复 分享
发布于 2019-04-06 21:33
第一题 ``` cpp #include <iostream> #include <vector> #include <string> #include <map> using namespace std; int slideWindow(const vector<int>& v) {     int cnt = 0;     int s = v.size();     for (int left = 0, right = 0; right < s; right++) {         if (v[right] == 0) {             left = right++;             continue;         }         int tL = left;         while (right - tL + 1 >= 5) {             int tmp = 1;             for (int l = tL; l <= right; l++) tmp *= v[l];             cnt += tmp;             tL++;         }     }     return cnt; } int main() {     int T = 0;     std::cin >> T;     while (T--) {         int num = 0;         cin >> num;         vector<int> v(14, 0);         while (num--) {             string t;             cin >> t;             int i = atoi(t.c_str());             if (i <= 10 && i >= 2)                 v[i]++;             else if (t == "A")                 v[t[0] - 'A' + 1]++;             else if (t == "J")                 v[11]++;             else if (t == "Q")                 v[12]++;             else v[13]++;                  }         std::cout << slideWindow(v) << std::endl;     } } ``` 第二题 ``` cpp #include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; string intToBin(int num) {     //if (num == 0) return "0";     string s(10, '0');     int i = 0;     while (num) {         int a = num & 1;         num >>= 1;         s[i++] = a + '0';     }     return s; } int binToInt(string& s) {     int ans = 0;     for (int i = 0; i < s.size(); i++) {         ans += (s[i] - '0') * pow(2, i);     }     return ans; } string Result(string& num) {     //if (num == 0) return "0";     string str = "";     int p = num.size();     while (p >= 0) {         int begin = p - 3 > 0 ? p - 3 : 0;         int end = p-1;         p -= 3;         string s1(num.substr(begin, end - begin + 1));         int n1 = atoi(s1.c_str());         str += intToBin(n1);     }     vector<string> vecStr;     int i = 0;     while(i < str.size()) {         string s;         int j = 5;         while (i < str.size() && j--) {             s.push_back(str[i++]);         }         vecStr.push_back(s);     }     string ret = "";     for (auto& v : vecStr) {         int num = binToInt(v);         if (num < 10) ret += num + '0';         else ret += 'A' + num - 10;     }     reverse(ret.begin(), ret.end());     i = 0;     while (ret[i] == '0') {         i++;     }     return ret.substr(i); } int main() {     int T = 0;     while (cin >> T) {         while (T--) {             string num;             cin >> num;             std::cout << Result(num) << std::endl;         }     } } ```
点赞 回复 分享
发布于 2019-04-06 21:35
import java.util.Scanner; import java.util.Vector; public class Main {     static public void main(String[] args) {         Scanner in = new Scanner(System.in);         int n = in.nextInt();         in.nextLine();         while (n-- > 0) {             // 第一次 补齐0             String string = in.nextLine();             if (string.length() % 3 == 1) {                 string = "00" + string;             } else if (string.length() % 3 == 2) {                 string = "0" + string;             }             // 将十进制转换成2进制             Vector<String> vector = new Vector<>();             int threeNum = string.length() / 3;             String tenStr = "";             for (int i = 0; i < threeNum; i++) {                 String temp = string.substring(i * 3, i * 3 + 3);                 temp = Integer.toString(Integer.parseInt(temp), 2);                 int tempLen = temp.length();                 for (int j = 0; j < 10 - tempLen; j++) {                     temp = "0" + temp;                 }                 tenStr = tenStr + temp;             }             // 去掉前导零             int tenStrLen = tenStr.length();             String tempStr = tenStr;             for (int i = 0; i < tenStrLen; i++) {                 if (tenStr.charAt(i) == '0') {                     tempStr = tenStr.substring(i + 1, tenStrLen);                 } else {                     break;                 }             }             tenStr = tempStr;             tenStrLen = tenStr.length();             for (int i = 0; i < tenStrLen; i++) {                 if (tenStr.charAt(i) == '0') {                     tempStr = tenStr.substring(i + 1, tenStrLen);                 } else {                     break;                 }             }             tenStrLen = tenStr.length();             int howManyFive = tenStr.length() % 5;             if (howManyFive != 0) {                 while (howManyFive++ < 5) {                     tenStr = "0" + tenStr;                 }             }             String result = "";             tenStrLen = tenStr.length();             int fiveTime = tenStrLen / 5;             while (fiveTime-- > 0) {                 result = Integer.toString(Integer.parseInt(tenStr.substring(5 * fiveTime, 5 * fiveTime + 5), 2), 32)                         + result;             }             System.out.println(result.toUpperCase());         }     } } 第二题 可以优化的点太多了……懒得继续优化了
点赞 回复 分享
发布于 2019-04-06 21:52
import java.util.Scanner; import java.util.Vector; public class Main { static public void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); in.nextLine(); while (n-- > 0) { // 第一次 补齐0 String string = in.nextLine(); if (string.length() % 3 == 1) { string = "00" + string; } else if (string.length() % 3 == 2) { string = "0" + string; } // 将十进制转换成2进制 Vector<String> vector = new Vector<>(); int threeNum = string.length() / 3; String tenStr = ""; for (int i = 0; i < threeNum; i++) { String temp = string.substring(i * 3, i * 3 + 3); temp = Integer.toString(Integer.parseInt(temp), 2); int tempLen = temp.length(); for (int j = 0; j < 10 - tempLen; j++) { temp = "0" + temp; } tenStr = tenStr + temp; } // 去掉前导零 int tenStrLen = tenStr.length(); String tempStr = tenStr; for (int i = 0; i < tenStrLen; i++) { if (tenStr.charAt(i) == '0') { tempStr = tenStr.substring(i + 1, tenStrLen); } else { break; } } tenStr = tempStr; tenStrLen = tenStr.length(); for (int i = 0; i < tenStrLen; i++) { if (tenStr.charAt(i) == '0') { tempStr = tenStr.substring(i + 1, tenStrLen); } else { break; } } tenStrLen = tenStr.length(); int howManyFive = tenStr.length() % 5; if (howManyFive != 0) { while (howManyFive++ < 5) { tenStr = "0" + tenStr; } } String result = ""; tenStrLen = tenStr.length(); int fiveTime = tenStrLen / 5; while (fiveTime-- > 0) { result = Integer.toString(Integer.parseInt(tenStr.substring(5 * fiveTime, 5 * fiveTime + 5), 2), 32) + result; } System.out.println(result.toUpperCase()); } } }
点赞 回复 分享
发布于 2019-04-06 21:53
#include <bits/stdc++.h> using namespace std; const int N = 200 + 5; int a[N]; vector <int> vec[N]; vector <int> fac[N]; vector <pair<double, double> > Node[N]; vector <pair<double, double> > tmp; bool vis[N]; double fini[N]; int n, m, B, E; void dfs(int v) {   tmp.clear();   if(v == B) {     vis[v] = 1; fini[v] = 1.0 * a[v] / (1.0 * E);     double flo = 0.0;     if(vec[v].size()) flo = 1.0 * E / (1.0 * vec[v].size());     tmp.push_back(make_pair(fini[v], flo));     Node[v] = tmp;     return ;   }   for(auto u: fac[v]) {     //cout << v << " " << u << endl;     if(!vis[u]) dfs(u);     for(auto x: Node[u]) {       tmp.push_back(x);       //cout << v << " " << u << " " << x.first << " " << x.second << endl;     }   }   vis[v] = 1;   if(tmp.size() == 0) {     fini[v] = -1.0; return ;   }   sort(tmp.begin(), tmp.end());   int tmpl = tmp.size();   double pre = 0.0;   double sum = 0.0;   int flg = -1;   for(int i = 0; i < tmpl-1; ++ i) {     pre += tmp[i].second;     double inv = tmp[i+1].first - tmp[i].first;     if(sum + inv*pre > 1.0 * a[v]) {       fini[v] = tmp[i].first + 1.0 * (1.0 * a[v] - sum) / pre;       flg = i; break;     }     sum += inv*pre;   }   if(flg == -1) {     double ptim = tmp[tmpl - 1].first;     //if(tmpl >= 2) ptim = tmp[tmpl - 2].first;     fini[v] = ptim + 1.0 * (1.0 * a[v] - sum) / (pre + tmp[tmpl - 1].second);     double fi = fini[v];     double se = pre + tmp[tmpl - 1].second;     tmp.resize(1);     tmp[0] = make_pair(fi, se / (1.0 * vec[v].size()));     Node[v] = tmp;     return ;   }   int nl = 0;   for(int i = flg; i < tmpl; ++ i) {     tmp[nl] = tmp[i];     tmp[nl].second = tmp[i].second / (1.0 * vec[v].size());     nl ++;   }   tmp[0].first = fini[v];   tmp[0].second = pre / (1.0 * vec[v].size());   tmp.resize(nl);   Node[v] = tmp;   return ; } int main() {   int T;   scanf("%d", &T);   while(T --) {     scanf("%d%d%d%d", &n, &m, &B, &E);     for(int i = 1; i <= n; ++ i) {       scanf("%d", a + i);       vec[i].clear();       fac[i].clear();       Node[i].clear();     }     for(int i = 1; i <= m; ++ i) {       int u, v;       scanf("%d%d", &u, &v);       vec[u].push_back(v);       fac[v].push_back(u);     }     memset(vis, 0, sizeof(vis));     for(int i = 1; i <= n; ++ i) {       if(!vis[i]) dfs(i);     }     for(int i = 1; i <= n; ++ i) {       printf("%.8f", fini[i]);       if(i != n) printf(" ");     }     printf("\n");   }   return 0; } 第三题,场上少写了个 nl++ 没过,还没改回来就时间到了 这是改完后的,不知道能不能过,希望哪位大佬能帮我看看
点赞 回复 分享
发布于 2019-04-06 22:04
第一题我也是本地都行,传上去就是0%。找了好久原因,后来发现我是用char来存输入,然后输入'10'的时候占两个字符,导致后面的输入都错位了。
点赞 回复 分享
发布于 2019-04-06 22:23

相关推荐

10-15 09:13
已编辑
天津大学 soc前端设计
点赞 评论 收藏
分享
10-06 12:46
门头沟学院 Java
跨考小白:定时任务启动
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务