目录
A.移动距离
【解析】根据题目可以画出如下的路径,那么最短距离就是下图的L+r的距离。
那么就转化成为了一个纯纯的数学题,考察数学知识,首先你需要知道弧长l=rθ,并且在直角三角形中,已知对边a和邻边b求角θ有这样的说法:若θ为一个锐角,根据正切函数的定义tanθ=a/b,则θ=arctan(a/b)。在C++库中有atan()函数跟atan2()函数可以求arctan函数(学好数学真的很重要!!!),代码如下:
#include<bits/stdc++.h>
using namespace std;
int main(){
double r=sqrt(233*233+666*666);
double q=atan(666.0/233);
int p=r*q+r;
cout<<p;
}
B.客流量上限
这道题本蒟蒻目前还没有理解,原本用暴力发现根本行不通,数据范围太大了,运行不出来,太难了,等我再理解理解理解,回来补题解(┭┮﹏┭┮)。
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int mod = 1e9+7;
int N =2025;
int qpow(int a,int b){
int res=1;
while(b){
if(b&1) res=res*a%mod;
a=a*a%mod;
b>>=1;
}
return res;
}
void solve(){
int tmp=qpow(2,N/2);
cout<<tmp<<endl;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T=1;
//cin>>T;
while(T--){
solve();
}
return 0;
}
C.可分解的正整数
【解析】我们先来手动打表来看一下,你会发现正整数中除了1之外都可以分解
(奉劝在座的各位一定要仔细读题,我把序列的至少看成只有了,所以这题暴力解了┭┮﹏┭┮,一定要仔细读题!!!┭┮﹏┭┮)
#include<bits/stdc++.h>
using namespace std;
int a[100010];
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++)
cin>>a[i];
int cnt=0;
for(int i=0;i<n;i++)
if(a[i]!=1)
cnt++;
cout<<cnt;
}
D.产值调整
【解析】这题看着就是一个简单的模拟,事实也是如此,但是数据范围很大,容易超时,那我们来打表找找规律,你会发现最后他都趋向一个值,这就是榜样学习的力量啊!!!
那么我们就可以进行剪枝了。
#include<bits/stdc++.h>
using namespace std;
int a,b,c,k;
void slove(){
cin>>a>>b>>c>>k;
int a1,b1,c1;
while(k--&&(a!=b||b!=c||a!=c)){
a1=floor(double(b+c)/2);
b1=floor(double(a+c)/2);
c1=floor(double(a+b)/2);
a=a1,b=b1,c=c1;
}
cout<<a<<" "<<b<<" "<<c<<endl;
}
int main(){
int t;
cin>>t;
while(t--){
slove();
}
}
E.画展布置
【解析】这道题我用了前缀和模拟了一下,但是一定要用1e18,0x3f3f3f3f是int的最大值,有一部分过不了!!!┭┮﹏┭┮
#include<bits/stdc++.h>
using namespace std;
const int N = 100010;
long long a[N],b[N];
int main(){
long long n,m;
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i];
b[i]=a[i]*a[i];
}
sort(b+1,b+n+1);
long long l=0,r=0, x=1e18;//这里要开long long 的最大值,如果开0x3f3f3f(int的最大值)不全对
for(int i=1;i<=n-m+1;i++){
long long tmp=b[i+m-1]-b[i];
if(tmp<x){
l=i;
r=i+m-1;
x=tmp;
}
}
long long res=b[r]-b[l];
cout<<res<<endl;
return 0;
}
F.水质检测
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int N = 1000010;
char c[2][N];
void solve(){
string a,b;
cin>>a>>b;
int n=a.size();
for(int i=0;i<n;i++){
c[0][i+1]=a[i];
c[1][i+1]=b[i];
}
int l,r; //l第一次出现#的列,r最后一次出现#的列
for(int i=1;i<=n;i++){
if(c[0][i]=='#'||c[1][i]=='#'){
l=i;
break;
}
}
for(int i=n;i>=1;i--){
if(c[0][i]=='#'||c[1][i]=='#'){
r=i;
break;
}
}
int res=0;
for(int i=l;i<=r-1;i++){
if(c[0][i]=='.'&&c[0][i+1]=='#'&&c[1][i]=='#'&&c[1][i+1]=='.'){
res++;
c[1][i+1]='#';
}else if(c[0][i]=='#'&&c[0][i+1]=='.'&&c[1][i]=='.'&&c[1][i+1]=='#'){
res++;
c[0][i+1]='#';
}else if(c[0][i]=='.'&&c[0][i+1]=='.'&&c[1][i]=='#'&&c[1][i+1]=='.'){
res++;
c[1][i+1]='#';
}else if(c[0][i]=='#'&&c[0][i+1]=='.'&&c[1][i]=='.'&&c[1][i+1]=='.'){
res++;
c[0][i+1]='#';
}else if(c[0][i]=='#'&&c[0][i+1]=='.'&&c[1][i]=='#'&&c[1][i+1]=='.'){
if(i<=n-2){
int num=-1;
for(int j=i+1;j<=n;j++){
if(c[0][j]=='#'){
num=0;
break;
}else if(c[1][j]=='#'){
num=1;
break;
}
}
if(num==0){
res++;
c[num][i+1]='#';
}else if(num==1){
res++;
c[num][i+1]='#';
}
}
}
}
cout<<res<<endl;
}
signed main(){
solve();
return 0;
}
G.生产车间
#include <bits/stdc++.h>
using namespace std;
void solve()
{
int n;
cin >> n;
vector<int> w(n + 1);
for (int i = 1; i <= n; i++)
{
cin >> w[i];
}
vector<vector<int>> adj(n + 1);
for (int i = 1; i <= n - 1; i++)
{
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
adj[0].push_back(1);
adj[1].push_back(0);
function<vector<bool>(int, int)> dfs = [&](int u, int fa) -> vector<bool>
{
vector<bool> f(w[u] + 1);
if (adj[u].size() == 1)
{
f[0] = true;
if (w[u] <= w[u])
f[w[u]] = true;
return f;
}
f[0] = true;
for (auto &v : adj[u])
{
if (v == fa)
continue;
vector<bool> g = dfs(v, u);
vector<bool> h(w[u] + 1);
for (int i = 0; i <= w[u]; i++)
{
if (!f[i])
continue;
for (int j = 0; j < g.size(); j++)
{
if (g[j] && i + j <= w[u])
h[i + j] = true;
}
}
f.swap(h);
}
return f;
};
vector<bool> res = dfs(1, 0);
int ans = 0;
for (int i = 0; i <= w[1]; i++)
{
if (res[i])
ans = max(ans, i);
}
cout << ans << "\n";
}
int main()
{
solve();
return 0;
}
H. 装修报价
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
ll qmi(ll x, ll k, ll p = mod)
{
x %= p;
ll res = 1;
while (k > 0)
{
if (k & 1)
res = (res * x) % p;
x = (x * x) % p;
k >>= 1;
}
return res;
}
void solve()
{
int n;
cin >> n;
vector<ll> a(n + 1);
vector<ll> preXor(n + 1, 0);
for (int i = 1; i <= n; i++)
{
cin >> a[i];
preXor[i] = preXor[i - 1] ^ a[i];
}
vector<ll> p3(n);
p3[0] = 1;
for (int i = 1; i < n; i++)
{
p3[i] = (p3[i - 1] * 3) % mod;
}
ll ans = preXor[n] % mod;
for (int i = 1; i < n; i++)
{
ll t = ((2ll * p3[n - 1 - i]) % mod * preXor[i]) % mod;
ans = (ans + t) % mod;
}
cout << (ans % mod + mod) % mod << "\n";
}
int main()
{
solve();
return 0;
}
没有解析的是本蒟蒻还没有完全理解,有疑点或者说不太会的,我会持续更新,尽量把没有解析的补上,如果有大佬会的话可以在评论区分享一下,相互进步,大家也可以说说本蒟蒻没有注意到的地方,开拓一下思路,最后祝大家不断学习,不断进步!!!