A:水题不解释不过我是对自己的菜有新的认识了
#include<cstring>
#include<cstdio>
#include<iostream>
#include<string>
#include<queue>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<functional>
using namespace std;
#define clr(a,b) memset(a,b,sizeof(a))
#define lowbit(x) x&-x
#define rep(a,b,c) for(ll a=b;a<c;a++)
#define dec(a,b,c) for(int a=b;a>c;a--)
#define eb(x) emplace_back(x)
#define pb(x) push_back(x)
#define ps(x) push(x)
#define MAX_N 100000+5
#define MAX_M 100
typedef long long ll;
typedef unsigned long long ull;
typedef priority_queue<ll,vector<ll>,greater<ll> >pqg;
const ll maxn=1000+5;
const ll inf=1e7;
ll mod=1e9+7;
int main()
{
#ifndef ONLINE_JUDGE
// freopen("data.txt","r",stdin);
#endif
int t;
cin>>t;
while(t--)
{
int n,m;
cin>>n>>m;
int smax=m,smin=m,tm=n-m+1;
if(tm>0)
{
smin=m/tm;
}
if(m%tm!=0)smin+=1;
if(n==m){smin=m;}
if(m==0){smin=0;}
printf("%d %d\n",smax,smin);
}
return 0;
}
C:模拟题记录每次操作i是寄存器的值是否被操作过被操作代表循环退出就好
#include <algorithm>
#include<cstdio>
#include<cstring>
#include<functional>
#include<iostream>
using namespace std;
#define clr(a,b) memset(a,b,sizeof(a))
const int maxn=1e5+1;
int mod=256;
struct Ope
{
char op[4];
int v,k;
} oper[10007];
int r,vis[256][10007];
int solve(int n)
{
r=0;
clr(vis,0);
int i=1;
while(i<=n)
{
if(vis[r][i])
{
return 0;
}
vis[r][i]=1;
switch(oper[i].op[1])
{
case 'd':
{
r+=oper[i].v%mod;
i++;
r%=mod;
break;
}
case 'e':
{
if(oper[i].v==r)
{
i=oper[i].k;
}
else
{
i++;
}
break;
}
case 'n':
{
if(oper[i].v!=r)
{
i=oper[i].k;
}
else
{
i++;
}
break;
}
case 'l':
{
if(r<oper[i].v)
{
i=oper[i].k;
}
else
{
i++;
}
break;
}
case 'g':
{
if(r>oper[i].v)
{
i=oper[i].k;
}
else
{
i++;
}
break;
}
default:
i++;
break;
}
}
return 1;
}
int main()
{
#ifndef ONLINE_JUDGE
// freopen("data.txt","r",stdin);
#endif
int t;
scanf("%d", &t);
while(t--)
{
int n;
scanf("%d", &n);
for(int i=1; i<=n; i++)
{
scanf("%s%d",&oper[i].op,&oper[i].v);
if(oper[i].op[0]!='a')
{
scanf("%d",&oper[i].k);
}
}
if(solve(n))
{
puts("Yes");
}
else
puts("No");
}
return 0;
}
H:前缀思想判断到i时是否与第i-1相同相同
#include<cstring>
#include<cstdio>
#include<iostream>
#include<string>
#include<queue>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<functional>
using namespace std;
#define clr(a,b) memset(a,b,sizeof(a))
#define lowbit(x) x&-x
#define rep(a,b,c) for(ll a=b;a<c;a++)
#define dec(a,b,c) for(int a=b;a>c;a--)
#define eb(x) emplace_back(x)
#define pb(x) push_back(x)
#define ps(x) push(x)
#define MAX_N 100000+5
#define MAX_M 100
typedef long long ll;
typedef unsigned long long ull;
typedef priority_queue<ll,vector<ll>,greater<ll> >pqg;
const ll maxn=1000+5;
const ll inf=1e7;
ll mod=1e9+7;
int main()
{
#ifndef ONLINE_JUDGE
// freopen("data.txt","r",stdin);
#endif
int t;
cin>>t;
while(t--)
{
string str;
cin>>str;
ll ans=(str[0]=='0'?2:1);
ll w=ans;
for(int i=1;i<str.size();i++)
{
if(str[i-1]==str[i]){w+=i*2;}
else {w+=i;}
if(str[i]=='1')w+=1;
else w+=2;
ans+=w;
}
cout<<ans<<endl;
}
return 0;
}
J:LCM 最小公倍数内一个循环
#include<cstring>
#include<cstdio>
#include<iostream>
#include<string>
#include<queue>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<functional>
using namespace std;
#define clr(a,b) memset(a,b,sizeof(a))
#define lowbit(x) x&-x
#define rep(a,b,c) for(ll a=b;a<c;a++)
#define dec(a,b,c) for(int a=b;a>c;a--)
#define eb(x) emplace_back(x)
#define pb(x) push_back(x)
#define ps(x) push(x)
#define MAX_N 100000+5
#define MAX_M 100
typedef long long ll;
typedef unsigned long long ull;
typedef priority_queue<ll,vector<ll>,greater<ll> >pqg;
const ll maxn=1000+5;
const ll inf=1e7;
ll mod=1e9+7;
ll a,b,c,d,v,t;
ll gcd(ll a,ll b)
{
if(a<b)
{
swap(a,b);
}
return b==0?a:gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
return a*b/gcd(a,b);
}
ll solve()
{
ll ans=b+d-1,tcon=0,lcmm=lcm(a,c);
ll tim=0;
ll ta=a,tc=c;
if(lcmm<=t)
{
while(ta<=lcmm||tc<=lcmm)
{
if(ta<=tc){tcon+=b-(ta-v>tim?1:0);tim=ta;ta+=a;}
else {tcon+=d-(tc-v>tim?1:0);tim=tc;tc+=c;}
}
ans+=t/lcmm*tcon;
t%=lcmm;tim=0;ta=a;tc=c;
}
while(ta<=t||tc<=t)
{
if(ta<=tc){ans+=b-(ta-v>tim?1:0);tim=ta;ta+=a;}
else {ans+=d-(tc-v>tim?1:0);tim=tc;tc+=c;}
}
return ans;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("data.txt","r",stdin);
#endif
int T;
scanf("%d",&T);
while(T--)
{
scanf("%lld%lld%lld%lld%lld%lld",&a,&b,&c,&d,&v,&t);
printf("%lld\n",solve());
}
return 0;
}
J:直接判断最高位相同的最多有多少个数就好
#include<cstring>
#include<cstdio>
#include<iostream>
#include<string>
#include<queue>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<functional>
using namespace std;
#define clr(a,b) memset(a,b,sizeof(a))
#define lowbit(x) x&-x
#define rep(a,b,c) for(ll a=b;a<c;a++)
#define dec(a,b,c) for(int a=b;a>c;a--)
#define eb(x) emplace_back(x)
#define pb(x) push_back(x)
#define ps(x) push(x)
#define MAX_N 100000+5
#define MAX_M 100
typedef long long ll;
typedef unsigned long long ull;
typedef priority_queue<ll,vector<ll>,greater<ll> >pqg;
const ll maxn=1000+5;
const ll inf=1e7;
ll mod=1e9+7;
int nums[MAX_N];
int main()
{
#ifndef ONLINE_JUDGE
// freopen("data.txt","r",stdin);
#endif
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
int maxx=0;
for(int i=0;i<n;i++)
{
scanf("%d",&nums[i]);
maxx=max(nums[i],maxx);
}
int ans=0;
for(int i=0;(1<<i)<=maxx;i++)
{
int tn=1<<i,tm=0;
for(int j=0;j<n;j++){if(tn&nums[j]&&nums[j]<(1<<(i+1)))tm++;}
ans=max(ans,tm);
}
printf("%d\n",ans);
}
return 0;
}