pow
点击查看代码
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll a,b,i,ans;
int main(){
freopen("pow.in","r",stdin);
freopen("pow.out","w",stdout);
scanf("%lld%lld",&a,&b);
if (a==1) return printf("1"),0;
ans=1;
for (i=1;i<=b;i++){
ans*=a;
if (ans>1e9) return printf("-1"),0;
}
return printf("%lld",ans),0;
}
decode
点击查看代码
#include <bits/stdc++.h>
#define ll long long
using namespace std;
void read(ll &x){
char c=getchar();
ll F=1;
while (c!='-' && (c<'0' || c>'9')) c=getchar();
if (c=='-') F=-1,x=0; else x=(c^48);
c=getchar();
while (c>='0' && c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
x*=F;
}
void write(ll x){
if (x<0) putchar('-'),x=-x;
if (x>9) write(x/10);
putchar(x%10+'0');
}
ll T;
namespace Solution1{
ll n,e,d,m,sum,i,to;
void go(){
while (T--){
read(n),read(e),read(d);
m=e*d-2,sum=n-m;
for (i=1,to=sqrt(n);i<=to;i++)
if (n%i==0)
if (i+n/i==sum){
write(i),putchar(' '),write(n/i),putchar('\n');
break;
}
if (i>to) puts("NO");
}
}
}
namespace Solution2{
ll n,e,d,m,sum,l,r,mid,ans;
void go(){
while (T--){
read(n),read(e),read(d);
m=e*d-2,sum=n-m;
l=1,r=sqrt(n),ans=-1;
while (l<=r){
mid=(l+r)>>1;
if (mid+n/mid<sum) r=mid-1;
else l=mid+1,ans=mid;
}
if (ans==-1 || ans+n/ans!=sum || n%ans!=0) puts("NO");
else write(ans),putchar(' '),write(n/ans),putchar('\n');
}
}
}
int main(){
// freopen("decode.in","r",stdin);
// freopen("decode.out","w",stdout);
read(T);
if (T<=1000) return Solution1::go(),0;
return Solution2::go(),0;
}
/*
(p[i]-1)*(q[i]-1)+1
p[i]*(q[i]-1)- 1*(q[i]-1)+1
p[i]*q[i]-p[i]*1-q[i]+1+1
p[i]*q[i]-p[i]-q[i]+2
e[i]*d[i]=p[i]*q[i]-p[i]-q[i]+2
e[i]*d[i]-2=p[i]*q[i]-p[i]-q[i]
10 0000 0000
*/
expr
点击查看代码
#include <bits/stdc++.h>
//#define ll long long
using namespace std;
const int N=1e6+5;
void write(int x){
if (x>9) write(x/10);
putchar(x%10+'0');
}
char a[N],b[N];
pair <int,int> c[N];
deque <char> vec;
deque <pair<int,int> > vec_ans;
int tmp_and,tmp_or,ls_and,ls_or,num,cnt,chr,i,n,tot,j,rcnt,now;
int main(){
freopen("expr.in","r",stdin);
freopen("expr.out","w",stdout);
scanf("%s",a+1);
n=strlen(a+1);
a[0]='(',a[++n]=')';
for (j=0;j<=n;j++){
vec.push_back(a[j]);
if (a[j]=='0' || a[j]=='1') vec_ans.push_back(make_pair(0,0));
if (a[j]==')'){
vec.pop_back(),tot=0;
while (vec.back()!='('){
b[++tot]=vec.back(),vec.pop_back();
if (b[tot]=='0' || b[tot]=='1')
c[tot]=vec_ans.back(),vec_ans.pop_back();
}
vec.pop_back();
cnt=-1,rcnt=-1;
tmp_and=0,tmp_or=0;
ls_and=0,ls_or=0;
b[tot+1]='y';
for (i=tot;i>=1;i--){
// cout<<b[i];
if (b[i]=='|' || b[i]=='&') continue;
now=(b[i]^48);
if (cnt==-1) cnt=now,ls_and+=c[i].first,ls_or+=c[i].second;
else if (b[i+1]=='&'){
if (cnt==0) ls_and++;
else ls_and+=c[i].first,ls_or+=c[i].second;
cnt&=now;
}
if (i-1==0 || b[i-1]=='|'){
if (rcnt==-1) rcnt=cnt,tmp_and+=ls_and,tmp_or+=ls_or;
else{
if (rcnt==1) tmp_or++;
else tmp_and+=ls_and,tmp_or+=ls_or;
rcnt|=cnt;
}
cnt=-1,ls_and=0,ls_or=0;
}
}
// cout<<"="<<rcnt<<"\n";
vec.push_back(rcnt+'0');
vec_ans.push_back(make_pair(tmp_and,tmp_or));
}
}
// cout<<vec.size()<<' '<<vec_ans.size()<<'\n';
// for (i=0;i<vec.size();i++) cout<<vec[i];cout<<'\n';
// for (i=0;i<vec_ans.size();i++) cout<<vec_ans[i].first<<' '<<vec_ans[i].second<<'\n';
putchar(vec.back()),putchar('\n');
write(vec_ans.back().first);
putchar(' ');
write(vec_ans.back().second);
return 0;
}
/*
& > |
0 | 1
1 0
0 2
*/
point
点击查看代码
#include <bits/stdc++.h>
//#define ll long long
using namespace std;
void read(int &x){
char c=getchar();
int F=1;
while (c!='-' && (c<'0' || c>'9')) c=getchar();
if (c=='-') F=-1,x=0; else x=(c^48);
c=getchar();
while (c>='0' && c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
x*=F;
}
void write(int x){
if (x<0) putchar('-'),x=-x;
if (x>9) write(x/10);
putchar(x%10+'0');
}
struct node{
int x,y;
} a[505];
int n,m,i,j,k,x,dp[505][505],ans,s,nn;
bool cmp(node x,node y){
return x.x<y.x || (x.x==y.x && x.y<y.y);
}
int check(int x,int y){
if (a[x].x>a[y].x || a[x].y>a[y].y) return 10000;
return a[y].x-a[x].x+a[y].y-a[x].y-1;
}
int main(){
freopen("point.in","r",stdin);
freopen("point.out","w",stdout);
read(n),read(m);
for (i=1;i<=n;i++) read(a[i].x),read(a[i].y);
sort (a+1,a+1+n,cmp);
for (i=1;i<=n;i++)
for (j=0;j<=m;j++){
dp[i][j]=1;
for (k=1;k<i;k++){
x=check(k,i);
if (j-x>=0)
dp[i][j]=max(dp[i][j],dp[k][j-x]+1);
}
ans=max(ans,dp[i][j]+m);
}
return write(ans),0;
}