入口
A Kyu in AtCoder
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t; cin>>t;
if(t>=1800) cout<<"1";
else if(t>=1600) cout<<"2";
else if(t>=1400) cout<<"3";
else if(t>=1200) cout<<"4";
else if(t>=1000) cout<<"5";
else if(t>=800) cout<<"6";
else if(t>=600) cout<<"7";
else if(t>=400) cout<<"8";
cout<<"\n";
return 0;
}
官方题解:
#include <iostream>
using namespace std;
int main() {
int X; cin >> X;
cout << 10 - X / 200 << endl;
return 0;
}
B Magic 2
#include<bits/stdc++.h> // 先把b放大,再把c放大
using namespace std;
int main()
{
int a,b,c,k;
cin>>a>>b>>c>>k;
while(k>0&&b<=a) k--,b*=2;
while(k>0&&c<=b) k--,c*=2;
if(c>b&&b>a) cout<<"Yes\n";
else cout<<"No\n";
return 0;
}
C Marks
#include<bits/stdc++.h> //模拟
using namespace std;
const int N = 2e5+7;
int a[N];
int main()
{
int n,k;
cin>>n>>k;
for(int i=1;i<=n;i++){
cin>>a[i];
if(i>k){
if(a[i]>a[i-k]) cout<<"Yes\n";
else cout<<"No\n";
}
}
return 0;
}
D Road to Millionaire
双指针。。,其实有更简便的角度切入,只可惜傻乎乎的模拟还调了半天。其实我们只考虑今天和明天的股票价格,只赚这两天的差价就OK了,这样不管它是的单调性是怎样的都能利益最大化。
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5+7;
LL a[N];
int main()
{
int n,t;
cin>>n;
LL ans=1000;
for(int k=1;k<=n;k++) cin>>a[k];
int i=1,j=2;
while(j<=n){
while(a[j]>=a[j-1]&&j<=n) j++;
if(j>n) {
j--;
ans = (ans/a[i])*a[j] + ans%a[i];
break;
}
j--;
ans = (ans/a[i])*a[j] + ans%a[i];
j++,i = j,j++;
}
cout<<ans<<"\n";
return 0;
}
官方题解1:
#include <iostream>
using namespace std;
long long N, A[87], CurrentMoney = 1000;
int main() {
cin >> N;
for (int i = 1; i <= N; i++) cin >> A[i];
for (int i = 1; i <= N - 1; i++) {
long long Stocks = 0;
if (A[i] < A[i + 1]) Stocks = CurrentMoney / A[i];
CurrentMoney += (A[i + 1] - A[i]) * Stocks;
}
cout << CurrentMoney << endl;
}
官方题解2:
#include <iostream>
#include <algorithm>
using namespace std;
long long N, A[87];
long long dp[87];
int main() {
cin >> N;
for (int i = 1; i <= N; i++) cin >> A[i];
dp[1] = 1000;
for (int i = 2; i <= N; i++) {
dp[i] = dp[i - 1];
for (int j = 1; j <= i - 1; j++) {
long long V = dp[j] / A[j];
long long W = dp[j] + (A[i] - A[j]) * V;
dp[i] = max(dp[i], W);
}
}
cout << dp[N] << endl;
return 0;
}
E M’s Solution (二进制枚举)
害,不开O2优化一直T,开了O2后勉强卡过去2926ms,O2O3双管齐下竟然1754ms,可以的。
思路:每个城市有两种选择——建路,不建路。而建路又有两种选择——建x方向、建y方向。所以直接二进制枚举,第一层01代表不建和建,当建的时候,第二层01代表建x方向和y方向。而n为15,复杂度还行。
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N = 20;
int x[N],y[N],p[N];
int dis[N];
LL ans[N];
int vis[N];
int main()
{
int n;scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d%d%d",&x[i],&y[i],&p[i]),ans[i]=1e18;
ans[0] = 1e18;
for(int i=0;i<(1<<n);i++){
int num=0; //此次建num条路
for(int j=0;j<n;j++) if((i>>j)&1) vis[++num] = j+1; //保存下来分别时那个城市
for(int j=0;j<(1<<num);j++){
for(int k=1;k<=n;k++) dis[k] = min(abs(x[k]),abs(y[k]));
for(int k=0;k<num;k++){
if((j>>k)&1){ //在num个road里选x方向建road
for(int t=1;t<=n;t++) dis[t] = min(dis[t],abs(x[t]-x[vis[k+1]]));
} //维护每个站到新road的最短距离
else{ //在num个road里选y方向建road
for(int t=1;t<=n;t++) dis[t] = min(dis[t],abs(y[t]-y[vis[k+1]]));
}
}
LL s=0;
for(int k=1;k<=n;k++) s += (LL)dis[k]*p[k];
ans[num] = min(ans[num],s);
}
}
for(int i=0;i<=n;i++) printf("%lld\n",ans[i]);
return 0;
}
F Air Safety
在这里插入代码片