机器学习派上了用场
#include
using namespace std;
int getsign(long long x){
return x<0?-1:1;
}
int main(int argc, char const *argv[])
{
int n;
int t;
cin>>n>>t;
map>> p;
int x,y;
char c;
for(int i=0; i>x>>y>>c;
p[c].push_back(make_pair(x,y));
}
while(t--){
long long a1,a2,a3;
cin>>a1>>a2>>a3;
long long A = a1+p['A'][0].first*a2+p['A'][0].second*a3;
long long B = a1+p['B'][0].first*a2+p['B'][0].second*a3;
if(getsign(A)==getsign(B)){
cout<<"No"<
双指针
#include
using namespace std;
int main(int argc, char const *argv[])
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
int a, b;
cin>>a>>b;
vector> X(a),Y(b);
long long ans = 0;
long long x,y;
for (int i = 0; i < a; ++i)
{
cin>>x>>y;
X[i] = make_pair(x,y);
}
for (int i = 0; i < b; ++i)
{
cin>>x>>y;
Y[i] = make_pair(x,y);
}
sort(X.begin(), X.end());
sort(Y.begin(), Y.end());
int i=0,j=0;
while(i
阅读理解题,后面太麻烦了
先骗四十分
#include
using namespace std;
string gets1(string s){
string res = "";
int l = 0;
int r = s.length()-1;
while(l<=r&&s[l]==' ') l++;
while(l<=r&&s[r]==' ') r--;
while(l<=r)
res += s[l++];
return res;
}
int main(int argc, char const *argv[])
{
string s;
int n;
// freopen("test.dat","r", stdin);
cin>>n;
// getchar();
int ans = 0;
int state = 0;
string temp = "";
int len = 0;
while(getline(cin,s)){
// cout<0)+1;
temp = "";
len = 0;
state = 0;
// cout<0)+1;
if(temp.length()){
// if(len%n!=0)
// cout<0)+1;
}
cout<
矩阵快速幂
能过96分,第一次接触矩阵快速幂
判重需要仔细考虑,两个的时候只能考虑单个数字生成
和相邻数字生成的新的对
#include
using namespace std;
const long long mod = 998244353;
vector> se={
{0,0,1,0,0,0,0,0,0,0,0,0,0,0},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,1,0,1,0,0,0,0,0,0,0,0,0,0},
{0,0,1,1,0,0,0,0,0,0,0,0,0,0},
{0,0,1,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,1,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,1,0,0},
{0,0,0,0,0,0,0,0,0,0,1,0,0,0},
{0,0,0,0,0,1,0,0,0,0,0,0,1,0},
{0,0,0,0,0,0,0,1,0,0,0,0,0,0},
{0,0,0,0,0,0,1,0,0,0,0,0,0,0},
{0,0,0,1,0,0,0,0,0,0,0,0,0,1},
{0,0,0,0,0,0,0,0,1,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,1,0,0,0,0}
};
// vector> seini = {{1,0,0,0,0,0,0,0,0,0,0,0,0,0}};
vector fi = {1,2,4,6,16,26,41,44,46,61,62,64,66,42};
vector> mmul(vector> a, vector> b){
int n = a.size();
int m = a[0].size();
int mm = b[0].size();
vector> aa(n, vector(mm, 0LL));
for(int i=0; i> matrix_mul(vector> a, int t){
vector> res(14, vector(14, 0LL));
for(int i=0; i<14; i++){
for(int j=0; j<14; j++){
res[i][j]=0;
if(i==j)
res[i][j]=1LL;
}
}
while(t){
if(t&1){
res = mmul(a,res);
}
a = mmul(a,a);
t = t>>1;
}
return res;
}
int main()
{
int n;
cin>>n;
string s;
cin>>s;
int targ = stoi(s);
se = matrix_mul(se, n);
for(int i=0; i<14; i++){
if(fi[i]==targ){
cout<
只会dfs暴力前四十分,但是不知道为啥只能过三十分
离谱了,想了一天也没看出来哪里错了,随缘了
#include
#define LL long long
using namespace std;
// 0表示不选
// 1表示选边界
// 2表示不选边界
vector> a(1100, vector(5,0));
LL n, m;
LL used[1100];
LL buy[1100];
LL ans = 0;
vector>> sss;
bool judge(){
for(auto ss:sss){
if(ss.second.second==1){
if(used[ss.first]&&!used[ss.second.first])
return false;
}else{
if(used[ss.first]==1&&!used[ss.second.first])
return false;
}
}
return true;
}
LL cal(){
LL res = 0;
for(LL i=1; i<=n; i++){
res += buy[i];
}
return res;
}
LL cal_2(LL i, LL x){
return a[i][2]*x*x+a[i][3]*x+a[i][4];
}
void dfs(LL i){
if(i==n+1){
if(judge())
ans = max(ans, cal());
// cout<a[i][0]&&tempa[i][0]&&tempa[i][0]&&temp>n>>m;
for(LL i=1; i<=n; i++){
cin>>a[i][0]>>a[i][1]>>a[i][2]>>a[i][3]>>a[i][4];
}
LL x,y,c;
for(LL i=0; i>c>>x>>y;
sss.push_back(make_pair(x,make_pair(y,c)));
}
dfs(1);
cout<