J组:
:
比较简单,大概是红红的难度,不浪费时间分析了
:
场上写了 ,状态转移方程:
后来老师告诉我得了 ,因为前面的结果会影响后面的。题解的思路是 时间复杂度 这我的确想不到,思路没打开。毕竟搜索时间复杂度 , 没多少人想到用搜索
比赛之后想到了下面的 但还是错的:
//Do not hack it
#include<bits/stdc++.h>
#define endl cerr<<"------------------I Love Sqrt Decomposition------------------\n";
#define int long long
using namespace std;
#ifdef __linux__
#define Gc getchar_unlocked
#define Pc putchar_unlocked
#endif
#ifndef __linux__
#define Gc getchar
#define Pc putchar
#endif
#define ds(x) (x=='\r'||x=='\n'||x==' ')
namespace g {
template<typename T> inline void r(T& a) { a = 0; char ch = Gc(); bool ok = 0; for (; ch < '0' || ch>'9';) { ok ^= (ch == '-'); ch = Gc(); }for (; ch >= '0' && ch <= '9';) { a = (a << 1) + (a << 3) + (ch ^ 48); ch = Gc(); }if (ok)a = -a; }
template<typename T> inline void w(T a) { if (a == 0) { Pc('0'); return; }static char ch[20]; int till = 0; if (a < 0) { Pc('-'); for (; a;) { ch[till++] = -(a % 10); a /= 10; } } else { for (; a;) { ch[till++] = a % 10; a /= 10; } }for (; till;)Pc(ch[--till] ^ 48); }
struct Srr {
Srr operator>>(int& a) { r(a); return{}; }
Srr operator>>(char& ch) { ch = Gc(); for (; ds(ch);) { ch = Gc(); }return{}; }
Srr operator>>(string& s) { s = ""; char ch = Gc(); for (; ds(ch);) { ch = Gc(); }for (; !(ds(ch) || ch == EOF);) { s.push_back(ch); ch = Gc(); }return {}; }
template<typename T> Srr operator<<(T& a) { r(a); return{}; }
void is(string& s, int T) { s = ""; char ch = Gc(); for (; ds(ch);) { ch = Gc(); }for (; T--;) { s.push_back(ch); ch = Gc(); } }
}in;
struct Sww {
Sww operator<<(const int a) { w(a); return{}; }
Sww operator<<(const char ch) { Pc(ch); return{}; }
Sww operator<<(const string s) { for (int i = 0; i < s.size(); i++) { Pc(s[i]); }return{}; }
template<typename T> Sww operator>>(const T a) { w(a); return{}; }
}out;
namespace __STL {
const bool __is_P[] = { 0,0,1,1,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,1 };
inline bool IP(const int a) { if (a <= 29) { return __is_P[a]; }if (a % 2 == 0 || a % 3 == 0 || a % 5 == 0) { return 0; }for (int i = 6;; i += 6) { if (((i + 1) * (i + 1)) > a) { return 1; }if (a % (i + 1) == 0) { return 0; }if (((i + 5) * (i + 5)) > a) { return 1; }if (a % (i + 5) == 0) { return 0; } } }
inline int power(int a, int b, const int mod = -1) { int ans = 1; if (mod == -1) { for (; b;) { if (b & 1) { ans *= a; }b >>= 1; a *= a; }return ans; }for (; b;) { if (b & 1) { ans = ans * a % mod; }b >>= 1; a = a * a % mod; }return ans; }
}
}using g::in; using g::out;
#undef ds
#undef Gc
#undef Pc
using namespace g::__STL;
#define eout cerr
int f[105];
signed main() {
f[1]=1;
f[2]=3;
#define n 100
for(int i=3;i<=n;i++){
f[i]=f[i>>1]+2;
if(i&1){
f[i]+=2;
}
for(int j=1;j<i;j++){
f[i]=min(f[i],f[j]+f[i-j]+1);
}
}
for(int i=1;i<=n;i++){
out<<i<<" ";
out<<f[i]<<'\n';
}
return 0;
}:
在之前的考试里见过,当时写了 的暴力,现在确实没想到更好的做法,所以又写了那个暴力
发现正解是我考场上的思路。我当时以为要用什么高级的数据结构来维护第一个 的数字,但题解里用双指针解决,确实是我想复杂了