h題
突然發現h題可以用好多種方法做的。
方法一
雙指標,維護乙個修改次數小於等於k的區間
#include
using
namespace std;
typedef
long
long ll;
const
int mod=
1e9+7;
const
int n=
1e5+5;
const
int inf=
0x3f3f3f3f
;const
int dx=
;const
int dy=
;typedef vectorvec;
typedef vectormat;
int n,k;
intsolve
(string s,
char ch)
else
l++; r++;}
}else
ans=
max(ans,r-l);}
return ans;
}int
main()
方法二
二分最大長度
#include
using
namespace std;
typedef
long
long ll;
const
int mod=
1e9+7;
const
int n=
2e5+5;
const
int inf=
0x3f3f3f3f
;const
int dx=
;const
int dy=
;typedef vectorvec;
typedef vectormat;
int n,k;
int dp[n][2
];bool
check
(int len)
return0;
}int
main()
int l=
1,r=n;
while
(lelse r=m-1;
} cout
}
方法三
序列自動機
#include
using
namespace std;
typedef
long
long ll;
const
int mod=
1e9+7;
const
int n=
2e5+5;
const
int inf=
0x3f3f3f3f
;const
int dx=
;const
int dy=
;typedef vectorvec;
typedef vectormat;
int n,k;
int nxt[n][2
],pos[2]
,num[2]
;int
main()
nxt[i-1]
[s[i]
-'0'
]=i;
}int ans=0;
for(
int i=
1;i<=n;i++
) cout
}
2020牛客寒假演算法基礎集訓營
長期更新,補完為止 2 g 判正誤 題意 t組資料。判斷a d b e c f是否等於g。1e9 a,b,c,g 1e9,0 d,e,f 1e9。保證不會出現指數和底數同為 0 的情況。思路 硬算會tle或mle。快速冪取模,為了增加過題概率,多取幾個模數判斷。includeusing namesp...
2020牛客寒假演算法基礎集訓營1
找規律,推公式 三角形個數為2 m n m n m 1 n 1 2 m n mn m 1 n 1 2 m n mn m 1 n 1 include include include include using namespace std typedef long long ll const int m...
2020牛客寒假演算法基礎集訓營1
a honoka和格點三角形 honoka最近在研究三角形計數問題。她認為,滿足以下三個條件的三角形是 好三角形 1.三角形的三個頂點均為格點,即橫座標和縱座標均為整數。2.三角形的面積為1 3.三角形至少有一條邊和 x軸或y 軸平行。honoka想知道,在平面中選取乙個大小為 的矩形格點陣,可以找...