快手开发笔试编程题
快手开发编程:
数据范围很搞 。
ll n,k; ll a[maxn]; string str; void solveip4(){ std::vector<int> v; int val = 0; for(int i = 0;i < sz(str);i++){ if(str[i] == '.') {v.pb(val),val = 0; if(i + 1 < sz(str) && str[i + 1] == '0' ) { wt("Neither");exit(0);} } else{ if(str[i] >= '0' || str[i] <= '9'){ val *= 10; val += str[i] - '0'; }else{ wt("Neither");exit(0); } } } v.pb(val); if(v.size() != 4){ wt("Neither");exit(0); } for(auto d:v){ if(d <= 255 && d >= 0) {} else { wt("Neither");exit(0); } } wt("IPv4"); } void solveip6(){ string now = ""; std::vector<string> v; for(int i = 0;i < sz(str);i++){ if(str[i] == ':'){ if(str[i + 1] == ':') {wt("Neither");exit(0);} v.pb(now);now = ""; }else now += str[i]; } v.pb(now); if(sz(v) != 8) {wt("Neither");exit(0);} for(auto d:v){ if((int)d.size() > 4) {wt("Neither"); exit(0);} if(d == "0000"){wt("Neither");exit(0);} else if(d == "000"){wt("Neither");exit(0);} else if(d == "00"){wt("Neither");exit(0);} } } int main() { ios; while(cin >> str){ int val = 0; int flag1 = 0; int flag2 = 0; std::vector<int> v; for(int i = 0;i < sz(str);i++){ if(str[i] == '.') flag1 = 1; else if(str[i] == ':') flag2 = 1; } if(flag1 && flag2) {wt("Neither");continue;} if(flag1){ solveip4(); }else{ solveip6(); wt("IPv6"); } } return 0; }
set<string>s; string op[30] = {"","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}; string now = ""; string str; void dfs(int cnt){ if(cnt == sz(str)) { s.insert(now); return ; } int x = str[cnt] - '1'; for(int i = 0;i < op[x].size();i++){ now += op[x][i]; dfs(cnt + 1); now.pop_back(); } } int main() { ios; while(cin >> str){ for(int i = 0;i < sz(str);i++) dfs(0); cout << "["; std::vector<string> v; for(auto d:s) v.pb(d); for(int i = 0;i < v.size() - 1;i++) cout << v[i] << ", "; cout << v.back(); cout << "]"; } return 0; }
ll a[maxn]; int f[maxn]; int main() { ios; while(cin >> n){ int sum = 0; fr1(i,1,n) cin >> a[i],sum += a[i]; f[0] = 1; for(int i = 1;i <= n;i++){ for(int j = sum;j >= 0;j--){ if(j - a[i] >= 0 && f[j - a[i]]) f[j] = 1; } } int ans = INF; for(int i = 1;i <= sum;i++) if(f[i]) ans = min(ans,abs(sum - i * 2)); wt(ans); } return 0; }
ll n,k; ll a[maxn]; int cnt[maxn]; int f[maxn]; int main() { ios; while(cin >> n){ int ans = 0,Max= 0; fr1(i,1,n) cin >> a[i],cnt[a[i]]++,ans = max(ans,cnt[a[i]]); sort(rg(a,1,n)); for(int i = 1;i <= 2005;i++){ MS0(f); for(int j = 1;j <= 2020;j++){ if(cnt[j]) { f[j] = 1; if(j > i) f[j] += f[j - i],ans = max(ans,f[j]); } } } wt(ans); } return 0; }