KYwlzr level
获赞
491
粉丝
12
关注
7
看过 TA
14
吉林大学
2017
C++
IP属地:未知
皮卡丘
私信
关注
2017-04-01 23:50
吉林大学 C++
1 2 3
投递去哪儿等公司10个岗位 >
0 点赞 评论 收藏
分享
2017-03-31 18:51
吉林大学 C++
0 点赞 评论 收藏
分享
2017-03-07 21:13
已编辑
吉林大学 C++
编程 40%(素数幂) 90%(序列) 100%(算法书) 求大神粘一下100%的前两题
stdc++:第一题: #include <iostream> #include <stdio.h> #include <string.h> #include <math.h> #include <algorithm> #include <string> #include <map> #include <vector> #include <set> #include <climits> #include <ctime> #include <cassert> #define IOS ios_base::sync_with_stdio(0); cin.tie(0); using namespace std; typedef long long ll; #define mp make_pair #define fi first #define se second #define pb push_back const double pi = acos(-1.0); const int inf = 0x3f3f3f3f; const ll INF = 0x3f3f3f3f3f3f3f3fll; const int MAX_N = 1001000; int prime_cnt; int vis[MAX_N], prime[MAX_N]; void Sieve() { memset(vis, 0, sizeof (vis)); prime_cnt = 0; for (int i = 2; i < MAX_N; ++i) { if (!vis[i]) prime[prime_cnt++] = i; for (int j = 0; j < prime_cnt && 1ll * i * prime[j] < MAX_N; ++j) { vis[i * prime[j]] = 1; if (i % prime[j] == 0) break; } } } ll n; bool isPrime(ll x) { for (int i = 2; 1ll * i * i <= x; ++i) { if (x % i == 0) return false; } return true; } int main() { Sieve(); while (~scanf("%lld", &n)) { if (n > 10000) { ll q = (ll)sqrt(n + 0.5); if (isPrime(q) && q * q == n) { printf("%lld %d\n", q, 2); continue; } else if (isPrime(q + 1) && (q + 1) * (q + 1) == n) { printf("%lld %d\n", q + 1, 2); continue; } else if (isPrime(q - 1) && (q - 1) * (q - 1) == n) { printf("%lld %d\n", q - 1, 2); continue; } } int exp = 0, flag = 0; ll x = n, ret = 1; for (int i = 0; i < prime_cnt; ++i) { if (x % prime[i] == 0) { int cnt = 0; while (x % prime[i] == 0) cnt++, x /= prime[i]; ret = prime[i]; if (x == 1 && cnt > 1) exp = cnt, flag = 1; break; } } if (flag) printf("%lld %d\n", ret, exp); else printf("No\n"); } return 0; } 第二题: #include <iostream> #include <stdio.h> #include <string.h> #include <math.h> #include <algorithm> #include <string> #include <map> #include <vector> #include <set> #include <climits> #include <ctime> #include <cassert> #define IOS ios_base::sync_with_stdio(0); cin.tie(0); using namespace std; typedef long long ll; #define mp make_pair #define fi first #define se second #define pb push_back const double pi = acos(-1.0); const int inf = 0x3f3f3f3f; const ll INF = 0x3f3f3f3f3f3f3f3fll; const int MAX_N = 10010; int main() { int n, L; while (~scanf("%d%d", &n, &L)) { int find = 0, st = -1, len = 0; for (int i = L - 1; i <= 100; ++i) { if (2 * n % (i + 1)) continue; int p = 2 * n / (i + 1) - i; if (p < 0 || (p % 2)) continue; st = p / 2, len = i + 1, find = 1; break; } if (find == 0) puts("No"); else { for (int i = 0; i < len; ++i) { printf("%d", i + st); if (i < len - 1) printf(" "); else printf("\n"); } } } return 0; } 第三题: #include <iostream> #include <stdio.h> #include <string.h> #include <math.h> #include <algorithm> #include <string> #include <map> #include <vector> #include <set> #include <climits> #include <ctime> #include <cassert> #define IOS ios_base::sync_with_stdio(0); cin.tie(0); using namespace std; typedef long long ll; #define mp make_pair #define fi first #define se second #define pb push_back const double pi = acos(-1.0); const int inf = 0x3f3f3f3f; const ll INF = 0x3f3f3f3f3f3f3f3fll; const int MAX_N = 10010; int n; ll num[15], pw[15]; int main() { pw[0] = 1; for (int i = 1; i < 15; ++i) pw[i] = pw[i - 1] * 10; while (~scanf("%d", &n)) { int digit[15], len = 0, x = n; while (x) { digit[len++] = x % 10; x /= 10; } memset(num, 0, sizeof (num)); for (int i = 1; i < digit[len - 1]; ++i) num[i] += pw[len - 1]; num[digit[len - 1]] += (n % pw[len - 1] + 1); for (int i = len - 2; i >= 1; --i) { int former = n % pw[i + 1], latter = n / pw[i]; for (int j = digit[i] + 1; j < 10; ++j) num[j] += 1ll * former * pw[i]; num[digit[i]] += 1ll * former * pw[i]; if (digit[i] > 0) num[digit[i]] += latter + 1; for (int j = 1; j < digit[i]; ++j) num[j] += pw[i] * (former + 1); if (digit[i] > 0) num[0] += 1ll * former * pw[i]; } if (n > 9) { ll former = n / pw[1]; int k = digit[0]; for (int i = k + 1; i < 10; ++i) num[i] += former; for (int i = 0; i <= k; ++i) num[i] += (former + 1); } num[0] -= 1; for (int i = 0; i < 10; ++i) { printf("%lld", num[i]); if (i < 9) putchar(' '); else putchar('\n'); } } return 0; }
投递牛客等公司10个岗位 >
0 点赞 评论 收藏
分享
2016-10-22 21:27
吉林大学 C++
每每面试官问起这样的问题,我都想日狗
lol....:上次面一个什么公司,到了hr说期望工资 我说了个20-24万结果hr直接问你还有什么要问的。。。。。
0 点赞 评论 收藏
分享
2016-09-11 09:12
已编辑
吉林大学 C++
0 点赞 评论 收藏
分享
2016-09-05 23:17
吉林大学 C++
0 点赞 评论 收藏
分享
2016-05-21 08:51
吉林大学 C++
0 点赞 评论 收藏
分享
2016-04-28 13:14
吉林大学 C++
0 点赞 评论 收藏
分享
关注他的用户也关注了:
牛客网
牛客企业服务