Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
我这段代码在poj居然过不了 有人能看下嘛 明明本地能过啊姿势有点丑 见谅 map<LL, int> m[2]; vector<LL> v[2]; for (auto p = m[0].begin(); p != m[0].end(); p++) { auto q = lower_bound(v[1].begin(), v[1].end(), -(*p).first); if (q != v[1].begin()) ..... } F:\temp\17837499.83020\Main.cpp(47) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int F:\temp\17837499.83020\Main.cpp(47) : error C2440: 'initializing' : cannot convert from 'std::_Tree<_Traits>::iterator' to 'int' with [ _Traits=std::_Tmap_traits<int,std::set<int>,std::less<int>,std::allocator<std::pair<const int,std::set<int>>>,false> ] No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called F:\temp\17837499.83020\Main.cpp(47) : error C2784: 'bool std::operator !=(const std::istreambuf_iterator<_Elem,_Traits> &,const std::istreambuf_iterator<_Elem,_Traits> &)' : could not deduce template argument for 'const std::istreambuf_iterator<_Elem,_Traits> &' from 'int' streambuf(557) : see declaration of 'std::operator !=' F:\temp\17837499.83020\Main.cpp(47) : error C2784: 'bool std::operator !=(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::vector<_Ty,_Alloc> &' from 'int' vector(1312) : see declaration of 'std::operator !=' 源代码: #include<set> #include<map> #include<cstdio> #include<vector> #include<iostream> #include<algorithm> #define mid (l+r)/2 #define mkpi(a,b) make_pair(a,b) #pragma warning(disable:4996) using namespace std; typedef long long LL; const int maxn = 40; int n, ansc; LL ans; LL a[maxn], absmn[2]; map<LL, int> m[2]; vector<LL> v[2]; void dfs(int deep, int start, int end, LL ans, int cnt, int flag) { if (deep == end + 1) { if (!ans && !cnt) return; absmn[flag] = min(absmn[flag], abs(ans)); if (!m[flag][ans]) { m[flag][ans] = cnt; //s[flag].insert(mkpi(ans, cnt)); v[flag].push_back(ans); } else m[flag][ans] = min(m[flag][ans], cnt); return; } dfs(deep + 1, start, end, ans + a[deep], cnt + 1, flag); dfs(deep + 1, start, end, ans, cnt, flag); } int main() { ios::sync_with_stdio(false); while (cin >> n&&n) { v[1].clear(); m[0].clear(); m[1].clear(); ansc = 0x3f3f3f3f; ans = 1e17; absmn[0] = absmn[1] = 1e17; for (int i = 1; i <= n; i++) cin >> a[i]; if (n == 1) { cout << a[1] << " 1" << '\n'; continue; } dfs(1, 1, (1 + n) / 2, 0, 0, 0); dfs((1 + n) / 2 + 1, (1 + n) / 2 + 1, n, 0, 0, 1); sort(v[1].begin(), v[1].end()); for (auto p = m[0].begin(); p != m[0].end(); p++) { auto q = lower_bound(v[1].begin(), v[1].end(), -(*p).first); //cout << (*p).first << endl; if (q != v[1].begin()) { auto q1 = q - 1; int cnt = 0; while (cnt++ <= 4) { if (ans == abs(*q1 + (*p).first)) ansc = min(ansc, (*p).second + m[1][*q1]); if (ans > abs(*q1 + (*p).first)) { ans = abs(*q1 + (*p).first); ansc = (*p).second + m[1][*q1]; } if (q1 == v[1].begin()) break; q1--; } } if (q != v[1].end()) { int cnt = 0; while (cnt++ <= 4 && q != v[1].end()) { if (ans == abs(*q + (*p).first)) ansc = min(ansc, (*p).second + m[1][*q]); if (ans > abs(*q + (*p).first)) { ans = abs(*q + (*p).first); ansc = (*p).second + m[1][*q]; } q++; } } } if (min(absmn[0], absmn[1]) <= ans) cout << min(absmn[0], absmn[1]) << " 1" << '\n'; else cout << ans << ' ' << ansc << '\n'; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator