生活随笔
收集整理的這篇文章主要介紹了
Acwing第 35 场周赛【完结】
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
目錄
- 4212. 字符串比較
- 4213. 最小結果【枚舉】
- 4214. 三元組【思維】
4212. 字符串比較
https://www.acwing.com/problem/content/4215/
#include<bits/stdc++.h>
using namespace std
;
int main(void)
{string a
,b
; cin
>>a
>>b
;for(int i
=0;i
<a
.size();i
++) a
[i
]=tolower(a
[i
]);for(int i
=0;i
<b
.size();i
++) b
[i
]=tolower(b
[i
]);if(a
>b
) puts("1");else if(a
==b
) puts("0");else puts("-1");return 0;
}
4213. 最小結果【枚舉】
https://www.acwing.com/problem/content/4216/
#include<bits/stdc++.h>
using namespace std
;
typedef long long int LL
;
const int N
=1e5*2+10;
const int mod
=1e9+7;
int n
,m
,t
;
LL a
[N
];
char op
[N
];
LL
get(LL s1
,LL s2
,char c
)
{if(c
=='+') return s1
+s2
;else return s1
*s2
;
}
int main(void)
{for(int i
=0;i
<4;i
++) cin
>>a
[i
];for(int i
=0;i
<3;i
++) cin
>>op
[i
];LL ans
=1e18;for(int i
=0;i
<4;i
++){for(int j
=i
+1;j
<4;j
++){vector
<LL
>ve
;for(int z
=0;z
<4;z
++){if(z
!=i
&&z
!=j
) ve
.push_back(a
[z
]);}ve
.push_back(get(a
[i
],a
[j
],op
[0]));for(int k1
=0;k1
<ve
.size();k1
++){vector
<LL
>temp
;for(int k2
=k1
+1;k2
<ve
.size();k2
++){for(int z
=0;z
<ve
.size();z
++){if(z
!=k1
&&z
!=k2
) temp
.push_back(ve
[z
]);}temp
.push_back(get(ve
[k1
],ve
[k2
],op
[1]));ans
=min(ans
,get(temp
[0],temp
[1],op
[2]));}}}}cout
<<ans
;
}
4214. 三元組【思維】
https://www.acwing.com/problem/content/4217/
很容易想到三維for,這顯然是不行的。我們需要減一維for。
故需要預處理結果來減一維。
#include<bits/stdc++.h>
using namespace std
;
const int N
=1e5+10;
typedef long long int LL
;
LL s
[N
],c
[N
],st
[N
],n
;
int main(void)
{cin
>>n
;memset(st
,-1,sizeof st
);for(int i
=0;i
<n
;i
++) cin
>>s
[i
];for(int i
=0;i
<n
;i
++) cin
>>c
[i
];for(int i
=0;i
<n
;i
++){for(int j
=i
+1;j
<n
;j
++){if(s
[i
]<s
[j
]&&(st
[i
]==-1||st
[i
]>c
[j
])) st
[i
]=c
[j
];}}LL ans
=1e12;for(int i
=0;i
<n
;i
++){for(int j
=i
+1;j
<n
;j
++){if(s
[i
]<s
[j
]&&st
[j
]!=-1) ans
=min(ans
,c
[i
]+c
[j
]+st
[j
]);}}if(ans
!=1e12) cout
<<ans
;else cout
<<-1;return 0;
}
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀
總結
以上是生活随笔為你收集整理的Acwing第 35 场周赛【完结】的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。