目录
打的挺好的。起晚了一小时也不是倒数。
L1-1 I LOVE WIT
请自行给出题面描述。
#include<bits/stdc++.h>
#define endl '\n'
#define mk make_pair
#define int long long
using namespace std;
typedef pair<int, int> PII;
const int N = 2e5+7;
const int mod=998244353;
const int inf=LLONG_MAX;
using i128=__int128;
void sovle(){
cout<<"I"<<endl;
cout<<endl;
cout<<" L"<<endl;
cout<<" O"<<endl;
cout<<" V"<<endl;
cout<<" E"<<endl;
cout<<endl;
cout<<" W"<<endl;
cout<<" I"<<endl;
cout<<" T"<<endl;
}
signed main()
{
ios::sync_with_stdio(false), cin.tie(0),cout.tie(0);
int t = 1;
//cin>>t;
while (t--){
sovle();
}
return 0;
}
L1-2 单位换算
若结果不为整数,只保留一位小数。
#include<bits/stdc++.h>
#define endl '\n'
#define mk make_pair
#define int long long
using namespace std;
typedef pair<int, int> PII;
const int N = 2e5+7;
const int mod=998244353;
const int inf=LLONG_MAX;
using i128=__int128;
void sovle(){
int n;
cin>>n;
n*=12;
double x=(1.0*n)*2.54*10;
if(ceil(x)==x and floor(x)==x){
printf("%0.f\n",x);
}else{
printf("%.1f\n",x);
}
}
signed main()
{
ios::sync_with_stdio(false), cin.tie(0),cout.tie(0);
int t = 1;
//cin>>t;
while (t--){
sovle();
}
return 0;
}
L1-3 Pokémon
闪光的概率固定为 1%,那,不闪光呢。。。。。。。99%。
#include<bits/stdc++.h>
#define endl '\n'
#define mk make_pair
#define int long long
using namespace std;
typedef pair<int, int> PII;
const int N = 2e5+7;
const int mod=998244353;
const int inf=LLONG_MAX;
using i128=__int128;
void sovle(){
double a[7];
for(int i=0;i<7;i++){
cin>>a[i];
char c;
cin>>c;
}
int c,f;
cin>>c>>f;
if(f==1){
double x=a[c]*0.01;
printf("%0.2f",x);
printf("%%");
}else{
double x=a[c]*0.99;
printf("%0.2f",x);
printf("%%");
}
}
signed main()
{
ios::sync_with_stdio(false), cin.tie(0),cout.tie(0);
int t = 1;
//cin>>t;
while (t--){
sovle();
}
return 0;
}
L1-4 颠倒阴阳
就按照题目要求模拟就好了。到最低位为止,之间的每一位取反,然后高低位翻转,输出结果的十进制表示。用字符串储存,反转好变,取反好变,十进制不会超出储存范围。就没了。
#include<bits/stdc++.h>
#define endl '\n'
#define mk make_pair
#define int long long
using namespace std;
typedef pair<int, int> PII;
const int N = 2e5+7;
const int mod=998244353;
const int inf=LLONG_MAX;
using i128=__int128;
int power(int a, int b) {
int res = 1;
for (; b; b /= 2, a = 1LL * a * a ) {
if (b % 2) {
res = 1LL*res*a;
}
}
return res;
}
void sovle(){
int n;
cin>>n;
string s="";
while(n!=0){
int x=n&1;
char c=x+'0';
n>>=1;
s+=c;
}
string ss="";
int nn=s.size();
for(int i=0;i<nn;i++){
if(s[i]=='1'){
ss+='0';
}else{
ss+='1';
}
}
reverse(ss.begin(),ss.end());
while(ss.size()<32){
ss="0"+ss;
}
int z=0;
nn=ss.size();
int sum=0;
for(int i=0;i<nn;i++){
if(ss[i]=='1'){
z=power(2,i);
sum+=z;
}
}
cout<<sum<<endl;
}
signed main()
{
ios::sync_with_stdio(false), cin.tie(0),cout.tie(0);
int t = 1;
//cin>>t;
while (t--){
sovle();
}
return 0;
}
L1-5 演唱会
细节,注意就好。不要抽风,不要把超过24的从0开始再计数。
#include<bits/stdc++.h>
#define endl '\n'
#define mk make_pair
#define int long long
using namespace std;
typedef pair<int, int> PII;
const int N = 2e5+7;
const int mod=998244353;
const int inf=LLONG_MAX;
using i128=__int128;
int power(int a, int b) {
int res = 1;
for (; b; b /= 2, a = 1LL * a * a ) {
if (b % 2) {
res = 1LL*res*a;
}
}
return res;
}
void sovle(){
int a,b,c;
char x;
cin>>a>>x>>b>>x>>c;
c+=33;
if(c>=60){
c%=60;
b++;
}
b+=22;
if(b>=60){
b%=60;
a++;
}
a+=1;
// cout<<a<<" "<<b<<" "<<c<<endl;
if(a>=19 and a<21){
cout<<"arrive late"<<endl;
return;
}if(a<19){
cout<<"arrive on time"<<endl;
return;
}if(a>=21){
cout<<"too late"<<endl;
return;
}
}
signed main()
{
ios::sync_with_stdio(false), cin.tie(0),cout.tie(0);
int t = 1;
//cin>>t;
while (t--){
sovle();
}
return 0;
}
L1-6 分鸽子
“一个人分到的鸽子肉不能来自于两只及以上的鸽子,因为这样会串味儿。”
二分,就结束了。看码。
#include<bits/stdc++.h>
#define endl '\n'
#define mk make_pair
#define int long long
using namespace std;
typedef pair<int, int> PII;
const int N = 2e5+7;
const int mod=998244353;
const int inf=LLONG_MAX;
using i128=__int128;
int n,m;
int a[100005];
bool check(int x){
if(x==0){
return true;
}
int sum=0;
for(int i=0;i<n;i++){
sum+=a[i]/x;
}
if(sum>=m){
return true;
}else{
return false;
}
}
void sovle(){
cin>>n>>m;
int maxn=0;
for(int i=0;i<n;i++){
cin>>a[i];
maxn=max(a[i],maxn);
}
int l=0,r=maxn;
int ans=0;
while(l<=r){
int mid=(l+r)/2;
if(check(mid)){
l=mid+1;
ans=mid;
}else{
r=mid-1;
}
}
cout<<ans<<endl;
}
signed main()
{
ios::sync_with_stdio(false), cin.tie(0),cout.tie(0);
int t = 1;
//cin>>t;
while (t--){
sovle();
}
return 0;
}
L1-7 拼接梯子
首先他拼不出奇数。因为这全是2的平方数。否则的话一定可以拼成。如果手里直接有等长的木棍。那么输出L,否则的话输出小于等于L的最大值。
#include<bits/stdc++.h>
#define endl '\n'
#define mk make_pair
#define int long long
using namespace std;
typedef pair<int, int> PII;
const int N = 2e5+7;
const int mod=998244353;
const int inf=LLONG_MAX;
using i128=__int128;
int power(int a, int b) {
int res = 1;
for (; b; b /= 2, a = 1LL * a * a ) {
if (b % 2) {
res = 1LL*res*a;
}
}
return res;
}
void sovle(){
int k,l;
cin>>k>>l;
//kduan cailiao
vector<int>a;
map<int,int>u;
int sum=0;
for(int i=1;i<=k;i++){
int x=power(2,i);
a.push_back(x);
u[x]++;
sum+=x;
}
sort(a.begin(),a.end());
if(l%2!=0 or sum<l){
cout<<"No"<<endl;
}else{
cout<<"Yes"<<endl;
int ans=0;
if(u[l]!=0){
cout<<l<<endl;
}else{
for(int i=0;i<k;i++){
if(a[i]<=l){
ans=a[i];
}else{
break;
}
}
}
cout<<ans<<endl;
}
}
signed main()
{
ios::sync_with_stdio(false), cin.tie(0),cout.tie(0);
int t = 1;
//cin>>t;
while (t--){
sovle();
}
return 0;
}
L1-8 幻想乡炼金学
有点无话可说。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dd(x) cout << #x << " = " << x << " "
#define de(x) cout << #x << " = " << x << endl
const ll mod = 1e9 + 7;
const int N = 1e5 + 7;
const int inf = 0x3f3f3f3f;
ll gcd(ll a,ll b){return b ? gcd(b,a % b) : a;}
string s,ss,sss;
int main()
{
getline(cin,s);
for(int i = 0;i < s.size();++i){
if(s[i] != ' '){
ss += s[i];
}
}
string tmp;
int cnt = 0;
for(int i = 0;i < ss.size();++i){
if(ss[i] <= 'Z' && ss[i] >= 'A' && tmp.size()){
sss += tmp;
tmp = "";
tmp += ss[i];
}
else if(ss[i] == '('){
sss += tmp;
tmp = "";
while(ss[++i] != ')')
tmp += ss[i];
i++;
cnt = 0;
while(ss[i] != '}'){
i++;
if(ss[i] <= '9' && ss[i] >= '0'){
cnt = cnt * 10 + ss[i] - '0';
}
}
string res = "";
for(int j = 0;j < tmp.size();++j){
if(tmp[j] >= 'A' && tmp[j] <= 'Z'){
res += tmp[j];j++;
while(j < tmp.size() && tmp[j] < 'A' || tmp[j] > 'Z'){
res += tmp[j];
++j;
}
j--;
}
for(int k = 0;k < cnt;++k)
sss += res;
res = "";
}
tmp = "";
}
else if(ss[i] == '{'){
cnt = 0;
while(ss[i] != '}'){
i++;
if(ss[i] <= '9' && ss[i] >= '0'){
cnt = cnt * 10 + ss[i] - '0';
}
}
for(int j = 0;j < cnt;++j)
sss += tmp;
tmp = "";
}
else{
tmp += ss[i];
}
}
sss += tmp;
cout << sss << endl;
return 0;
}
L2-1 特殊的沉重球
dfs
我们可以先从大到小排序。因为我们先选择大的,后面的选择就会减少,分支也会减少。相反,如果先搜索小的,后面的选择多,搜索的分支会变多。
#include<bits/stdc++.h>
#define endl '\n'
#define mk make_pair
#define int long long
using namespace std;
typedef pair<int, int> PII;
const int N = 2e5+7;
const int mod=998244353;
const int inf=LLONG_MAX;
using i128=__int128;
int n,w;
int a[25];
int sum[25];
int ans=20;
void dfs(int u,int k){
if(k>=ans){
return;
}if(u==n){
ans=k;
}
for(int i=0;i<k;i++){
if(sum[i]+a[u]<=w){
sum[i]+=a[u];
dfs(u+1,k);
sum[i]-=a[u];
}
}
sum[k]=a[u];
dfs(u+1,k+1);
sum[k]=0;
}
void sovle(){
cin>>n>>w;
for(int i=0;i<n;i++){
cin>>a[i];
}
ans=n;
sort(a,a+n);
reverse(a,a+n);
dfs(0,0);
cout<<ans<<endl;
}
signed main()
{
ios::sync_with_stdio(false), cin.tie(0),cout.tie(0);
int t = 1;
//cin>>t;
while (t--){
sovle();
}
return 0;
}
L2-2 又见火车入栈
因为存在查询前y项记录用STL的stack肯定是不行的,只能手写一个栈,并且可以发现,查询和我进出栈没关系,考虑离线。
对于每个输入的查询,用一个数组a保存,在模拟进出栈的情况,模拟到第k条记录时,停止,这里要考虑输入不是递增,需要将查询数组按照记录升序先排序在查询,将答案更新为当前入栈的第y辆火车
#include<bits/stdc++.h>
#define endl '\n'
#define mk make_pair
#define int long long
using namespace std;
typedef pair<int, int> PII;
const int N = 1e6+1;;
const int mod=998244353;
const int inf=LLONG_MAX;
using i128=__int128;
int ans[N];
struct xun{
int x,y,bian;
};
bool cmp1(xun a, xun b){
return a.x<b.x;
}
bool cmp2(pair<int,int>a,pair<int,int>b){
return a.second<b.second;
}
void sovle(){
int n;
cin>>n;
vector<int>s(n);
for(int i=0;i<n;i++){
string zzzzz;
cin>>zzzzz;
if(zzzzz=="in"){
s[i]=1;
}else{
s[i]=0;
}
}
int q;
cin>>q;
vector<xun>z(q);
for(int i=0;i<q;i++){
cin>>z[i].x>>z[i].y;
z[i].bian=i;
}
sort(z.begin(),z.end(),cmp1);
vector<int>a;
int k=1;
int j=0;
for(int i=0;i<n;i++){
if(s[i]==1){
a.push_back(k);
k++;
}else{
a.pop_back();
}
while(i+1==z[j].x and j<q){
ans[z[j].bian]=a[z[j].y-1];
j++;
}
if(j==q){
break;
}
}
for(int i=0;i<q;i++){
cout<<ans[i]<<endl;
}
}
signed main()
{
ios::sync_with_stdio(false), cin.tie(0),cout.tie(0);
int t = 1;
//cin>>t;
while (t--){
sovle();
}
return 0;
}