1309 条题解
-
-1hjxhjx LV 6 @ 2019-07-10 11:46:08
废话少说,高精,上!!!(C++)
#include<bits/stdc++.h>//万能头 using namespace std; int a1[1000],a2[1000],c[1000]; int main(){ string s1,s2; int l1,l2,lc; cin>>s1>>s2;//输入 l1=s1.size(); l2=s2.size(); lc=max(l1,l2); for(int i=0;i<=l1-1;i++){ a1[i]=s1[l1-i-1]-'0'; } for(int i=0;i<=l2-1;i++){ a2[i]=s2[l2-i-1]-'0'; } for(int i=0;i<=lc-1;i++){ c[i]+=a1[i]+a2[i]; if(c[i]>=10){ c[i]%=10; c[i+1]++; } } if(c[lc]!=0) lc++; while(c[lc-1]==0 && lc!=1) lc--; //防止最高位为零 for(int i=lc-1;i>=0;i--) cout<<c[i]; //输出 return 0; }
LCT:
#include<iostream> #include<cstring> #include<cstdio> #include<cstring> using namespace std; struct node { int data,rev,sum; node *son[2],*pre; bool judge(); bool isroot(); void pushdown(); void update(); void setson(node *child,int lr); }lct[233]; int top,a,b; node *getnew(int x) { node *now=lct+ ++top; now->data=x; now->pre=now->son[1]=now->son[0]=lct; now->sum=0; now->rev=0; return now; } bool node::judge(){return pre->son[1]==this;} bool node::isroot() { if(pre==lct)return true; return !(pre->son[1]==this||pre->son[0]==this); } void node::pushdown() { if(this==lct||!rev)return; swap(son[0],son[1]); son[0]->rev^=1; son[1]->rev^=1; rev=0; } void node::update(){sum=son[1]->sum+son[0]->sum+data;} void node::setson(node *child,int lr) { this->pushdown(); child->pre=this; son[lr]=child; this->update(); } void rotate(node *now) { node *father=now->pre,*grandfa=father->pre; if(!father->isroot()) grandfa->pushdown(); father->pushdown();now->pushdown(); int lr=now->judge(); father->setson(now->son[lr^1],lr); if(father->isroot()) now->pre=grandfa; else grandfa->setson(now,father->judge()); now->setson(father,lr^1); father->update();now->update(); if(grandfa!=lct) grandfa->update(); } void splay(node *now) { if(now->isroot())return; for(;!now->isroot();rotate(now)) if(!now->pre->isroot()) now->judge()==now->pre->judge()?rotate(now->pre):rotate(now); } node *access(node *now) { node *last=lct; for(;now!=lct;last=now,now=now->pre) { splay(now); now->setson(last,1); } return last; } void changeroot(node *now) { access(now)->rev^=1; splay(now); } void connect(node *x,node *y) { changeroot(x); x->pre=y; access(x); } void cut(node *x,node *y) { changeroot(x); access(y); splay(x); x->pushdown(); x->son[1]=y->pre=lct; x->update(); } int query(node *x,node *y) { changeroot(x); node *now=access(y); return now->sum; } int main() { scanf("%d%d",&a,&b); node *A=getnew(a); node *B=getnew(b); //连边 Link connect(A,B); //断边 Cut cut(A,B); //再连边orz Link again connect(A,B); printf("%d\n",query(A,B)); return 0; }
正解:
#include<bits/stdc++.h> using namespace std; int main(){ int a,b; cin>>a>>b; cout<<a+b; return 0; }
-
-12019-07-09 09:23:27@
splay.
#include <bits/stdc++.h> #define ll long long #define N 100000 using namespace std; int sz[N], rev[N], tag[N], sum[N], ch[N][2], fa[N], val[N]; int n, m, rt, x; void push_up(int x){ sz[x] = sz[ch[x][0]] + sz[ch[x][1]] + 1; sum[x] = sum[ch[x][1]] + sum[ch[x][0]] + val[x]; } void push_down(int x){ if(rev[x]){ swap(ch[x][0], ch[x][1]); if(ch[x][1]) rev[ch[x][1]] ^= 1; if(ch[x][0]) rev[ch[x][0]] ^= 1; rev[x] = 0; } if(tag[x]){ if(ch[x][1]) tag[ch[x][1]] += tag[x], sum[ch[x][1]] += tag[x]; if(ch[x][0]) tag[ch[x][0]] += tag[x], sum[ch[x][0]] += tag[x]; tag[x] = 0; } } void rotate(int x, int &k){ int y = fa[x], z = fa[fa[x]]; int kind = ch[y][1] == x; if(y == k) k = x; else ch[z][ch[z][1]==y] = x; fa[x] = z; fa[y] = x; fa[ch[x][!kind]] = y; ch[y][kind] = ch[x][!kind]; ch[x][!kind] = y; push_up(y); push_up(x); } void splay(int x, int &k){ while(x != k){ int y = fa[x], z = fa[fa[x]]; if(y != k) if(ch[y][1] == x ^ ch[z][1] == y) rotate(x, k); else rotate(y, k); rotate(x, k); } } int kth(int x, int k){ push_down(x); int r = sz[ch[x][0]]+1; if(k == r) return x; if(k < r) return kth(ch[x][0], k); else return kth(ch[x][1], k-r); } void split(int l, int r){ int x = kth(rt, l), y = kth(rt, r+2); splay(x, rt); splay(y, ch[rt][1]); } void rever(int l, int r){ split(l, r); rev[ch[ch[rt][1]][0]] ^= 1; } void add(int l, int r, int v){ split(l, r); tag[ch[ch[rt][1]][0]] += v; val[ch[ch[rt][1]][0]] += v; push_up(ch[ch[rt][1]][0]); } int build(int l, int r, int f){ if(l > r) return 0; if(l == r){ fa[l] = f; sz[l] = 1; return l; } int mid = l + r >> 1; ch[mid][0] = build(l, mid-1, mid); ch[mid][1] = build(mid+1, r, mid); fa[mid] = f; push_up(mid); return mid; } int asksum(int l, int r){ split(l, r); return sum[ch[ch[rt][1]][0]]; } int main(){ //总共两个数 n = 2; rt = build(1, n+2, 0);//建树 for(int i = 1; i <= n; i++){ scanf("%d", &x); add(i, i, x);//区间加 } rever(1, n);//区间翻转 printf("%d\n", asksum(1, n));//区间求和 return 0; }
-
-12019-06-27 12:54:21@
#include<bits/stdc++.h> using namespace std; const int TT=10000; inline int read(){ int ret=0,f=1;char ch=getchar(); while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();} while(isdigit(ch)) ret=ret*10+ch-'0',ch=getchar(); return ret; } struct xx{ int a[3005],len; xx(){len=0;memset(a,0,sizeof a);} xx(int x){ len=0;memset(a,0,sizeof a); do{a[++len]=x%TT,x/=TT;}while(x); } xx operator+(const xx b){ xx c;c.len=max(len,b.len); for(int i=1;i<=c.len;i++){ c.a[i]+=a[i]+b.a[i]; c.a[i+1]+=c.a[i]/TT; c.a[i]%=TT; } if(c.a[c.len+1]) c.len++; return c; } void print(){ printf("%d",a[len]); for(int i=len-1;i>=1;i--)printf("%04d",a[i]); printf("\n"); } }a,b,c; int main(){ a=read(),b=read(); c=a+b; c.print(); return 0; }
-
-12019-06-22 01:00:12@
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <climits>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
#include <ctime>
#include <string>
#include <cstring>
using namespace std;
const int N=405;
struct Edge {
int v,w;
};
vector<Edge> edge[N*N];
int n;
int dis[N*N];
bool vis[N*N];
struct cmp {
bool operator()(int a,int b) {
return dis[a]>dis[b];
}
};
int Dijkstra(int start,int end)
{
priority_queue<int,vector<int>,cmp> dijQue;
memset(dis,-1,sizeof(dis));
memset(vis,0,sizeof(vis));
dijQue.push(start);
dis[start]=0;
while(!dijQue.empty()) {
int u=dijQue.top();
dijQue.pop();
vis[u]=0;
if(u==end)
break;
for(int i=0; i<edge[u].size(); i++) {
int v=edge[u][i].v;
if(dis[v]==-1 || dis[v]>dis[u]+edge[u][i].w) {
dis[v]=dis[u]+edge[u][i].w;
if(!vis[v]) {
vis[v]=true;
dijQue.push(v);
}
}
}
}
return dis[end];
}
int main()
{
int a,b;
scanf("%d%d",&a,&b);
Edge Qpush;Qpush.v=1;
Qpush.w=a;
edge[0].push_back(Qpush);Qpush.v=2;
Qpush.w=b;
edge[1].push_back(Qpush);printf("%d",Dijkstra(0,2));
return 0;
} -
-12019-05-26 16:06:36@
来发字典树
#include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> using namespace std; struct node{ int str[26]; int sum; }s[1000]; char str1[100]; int t=0,tot=0,ss=0; bool f1; void built() { t=0; for(int i=0;i<strlen(str1);i++) { if(str1[i]=='-'){ f1=true;continue; } if(!s[t].str[str1[i]-'0']) s[t].str[str1[i]-'0']=++tot; t=s[t].str[str1[i]-'0']; s[t].sum=str1[i]-'0'; } } int query() { int t=0;int s1=0; for(int i=0;i<strlen(str1);i++) { if(str1[i]=='-') continue; if(!s[t].str[str1[i]-'0']) return s1; t=s[t].str[str1[i]-'0']; s1=s1*10+s[t].sum; } return s1; } int main() { for(int i=1;i<=2;i++) { f1=false; scanf("%s",str1); built(); if(f1) ss-=query(); else ss+=query(); } printf("%d",ss); return 0; }
-
-12019-03-25 22:13:11@
#include <iostream>
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
cout << a + b << endl;
} -
-12019-03-25 20:00:53@
#include<cstdio> int main(){ int a,b; scanf("%d%d",&a,&b); printf("%d",a+b); return 0; }
-
-12019-03-25 19:59:39@
#include<cstdio> int a[-1u]; int main(){ int a,b; scanf("%d%d",&a,&b); printf("%d",a+b); return 0; }
-
-12019-03-25 19:49:38@
大家都太不正常了
我个小蒟蒻瑟瑟发抖
代码也瑟瑟发抖#include<iostream> #include<algorithm> #include<cmath> #include<cstdlib> #include<cstdio> #include<cstring> #include<queue> #define ll long long #define in read(); using namespace std; namespace FastIO{ const ll L=1<<15; char buffer[L],*S,*T; inline char getchar(){ if(S==T){T=(S=buffer)+fread(buffer,1,L,stdin);if(S==T)return EOF;} return *S++; } inline ll read(){ char c=getchar();ll rec=0,f=1; while(!isdigit(c)) {if(c=='-')f=-1;c=getchar();} while(isdigit(c))rec=(rec<<1)+(rec<<3)+(c^'0'),c=getchar(); return rec*f; } }using FastIO::read; const ll N=110000; ll first[N],size=0; struct date{ll to,next,len;}bian[N<<1]; void add(ll x,ll y,ll z){ size++; bian[size].next=first[x]; first[x]=size; bian[size].to=y; bian[size].len=z; } ll n,m,Q; ll a,b,c; //long long !!!! ll dis[N],dep[N],fa[N][21]; ll lca(ll x,ll y) { if(dep[x]<dep[y]) swap(x,y); ll t=dep[x]-dep[y]; for(ll i=0;i<20;i++) if((1<<i)&t) x=fa[x][i]; if(x==y) return x; ll j=19; while(fa[x][0]!=fa[y][0]) { if(fa[x][j]!=fa[y][j]) x=fa[x][j],y=fa[y][j]; j--; } return fa[x][0]; } ll ST[N][20],dfs_clock=0,pos[N]; ll DD(ll x,ll y) { ll l=pos[x],r=pos[y]; if(l>r)swap(l,r); ll L=floor(log2(r-l+1)); return min(ST[l][L],ST[r-(1<<L)+1][L]); } ll dist(ll x,ll y) { return dis[x]+dis[y]-2*DD(x,y); } void dfs(ll u,ll lst) { ST[++dfs_clock][0]=dis[u]; pos[u]=dfs_clock; for(ll i=first[u];i;i=bian[i].next) { ll to=bian[i].to; if(to==lst) continue; dep[to]=dep[u]+1; dis[to]=dis[u]+bian[i].len; fa[to][0]=u; dfs(to,u); ST[++dfs_clock][0]=dis[u]; } } void S_T() { for(ll j=1;j<20;j++) for(ll i=1;i<=n;i++) fa[i][j]=fa[fa[i][j-1]][j-1]; for(ll j=1;j<19;j++) for(ll i=1;i+(1<<j)<=n;i++) ST[i][j]=min(ST[i][j-1],ST[i+(1<<(j-1))][j-1]); } ll vis[N],d[N]; ll getpos(ll s) { queue<ll>q; memset(vis,0,sizeof(vis)); memset(d,0,sizeof(dis)); q.push(s); ll Max=0,p; while(!q.empty()) { ll u=q.front();q.pop(); if(vis[u]) continue; vis[u]=1; if(d[u]>Max) p=u,Max=d[u]; for(ll i=first[u];i;i=bian[i].next) { ll to=bian[i].to; if(vis[to]) continue; d[to]=d[u]+bian[i].len; q.push(to); } } return p; } ll core[N],s[N],D[N][21]; ll up_find(ll x,ll top,ll q) { if(s[x]>=q) return x; if(x==top) return -1; ll Max=0; for(ll j=19;j>=0;j--) if(fa[x][j] && D[x][j]<q && dep[fa[x][j]]>=dep[top]) x=fa[x][j]; if(s[x]>=q) return x; if(x!=top && s[fa[x][0]]>=q) return fa[x][0]; return -1; } ll the_max(ll x,ll to) { if(x==to) return s[x]; if(dep[to]>dep[x]) swap(x,to); ll t=dep[x]-dep[to]; ll Max=s[x]; for(ll j=19;j>=0;j--) if(fa[x][j] && dep[fa[x][j]]>=dep[to]) Max=max(Max,D[x][j]),x=fa[x][j]; return Max; } ll down_find(ll x,ll top,ll q) { if(x==top) { if(s[x]>=q) return x; return -1; } ll t=dep[x]-dep[top]; ll l=0,r=t,ans=-1,mid,temp=x; while(l<=r) { mid=l+r>>1; //cout<<mid<<endl; temp=x; for(ll j=0;j<19;j++) if(mid&(1<<j)) temp=fa[temp][j]; // cout<<temp<<' '<<top<<' '<<the_max(temp,top)<<endl; if(the_max(temp,top) >= q) ans=temp,l=mid+1; else r=mid-1; } return ans; } ll query(ll x,ll y,ll q) { ll top=lca(x,y); //cout<<top<<endl; if(top==x) { //cout<<"???????"; return down_find(y,top,q); // } ll t=up_find(x,top,q); if(t!=-1) return t; t=down_find(y,top,q); return t; } int main() { // freopen("test.in","r",stdin); // freopen("shelter.out","w",stdout); n=in; Q=in; a=in; b=in; c=in; for(ll i=1,x,y,z;i<n;i++) { x=in;y=in;z=in; add(x,y,z);add(y,x,z); } dfs(1,0); S_T(); ll s1=getpos(1); ll s2=getpos(s1); ll L=dist(s1,s2); ll tot=0; for(ll i=1;i<=n;i++) if(dist(s1,i)==L || dist(s2,i)==L) core[++tot]=i; memset(d,0,sizeof(d)); for(ll i=1;i<=n;i++) { for(ll j=1;j<=tot;j++) d[i]=max(d[i],dist(i,core[j])); //?????????? s[i]=1ll*(d[i]+a) * b % c; } for(ll i=1;i<=n;i++) D[i][0]=s[fa[i][0]]; for(ll j=1;j<19;j++) for(ll i=1;i<=n;i++) D[i][j]=max(D[i][j-1],D[fa[i][j-1]][j-1]); ll x,y,z; // for(ll i=1;i<=n;i++) cout<<s[i]<<' ';cout<<endl; // cout<<the_max(5,1)<<endl; while(Q--) { x=in; y=in; z=in; printf("%lld\n",query(x,y,z)); } return 0; }
-
-12019-03-05 15:59:51@
cin >> a >> b;
cout << a + b << endl; 即可。这样输出的是 \(a + b\) -
-12019-02-12 15:14:54@
#include<bits/stdc++.h> using namespace std; int a;int b; void write(int x){ if(x==0){putchar(48);return;} int len=0,dg[20]; while(x>0){dg[++len]=x%10;x/=10;} for(int i=len;i>=1;i--)putchar(dg[i]+48); } inline bool read(int &num) { char in;bool IsN=false; in=getchar(); if(in==EOF) return false; while(in!='-'&&(in<'0'||in>'9')) in=getchar(); if(in=='-'){ IsN=true;num=0;} else num=in-'0'; while(in=getchar(),in>='0'&&in<='9'){ num*=10,num+=in-'0'; } if(IsN) num=-num; return true; } int main() { read(a); read(b); write(a+b); return 0; }
已经很快了吧qaq
快读加快输(毒瘤 -
-12018-12-22 15:44:55@
#include<iostream>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
cout<<a+b<<endl;
} -
-12018-11-13 22:17:24@
看到题解并不水,发现自己想简单了,应该是数据水
-
-12018-11-09 21:58:08@
天生爱恶搞
咋地?咬我?
啦啦啦啦啦啦啦啦啦啦啦啦……#@\(#^%\)@@!
好,开始我们的代码
Dijkstra+STL优先队列优化。
```cpp
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <climits>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
#include <ctime>
#include <string>
#include <cstring>
using namespace std;
const int N=405;
struct Edge {
int v,w;
};
vector<Edge> edge[N*N];
int n;
int dis[N*N];
bool vis[N*N];
struct cmp {
bool operator()(int a,int b) {
return dis[a]>dis[b];
}
};
int Dijkstra(int start,int end)
{
priority_queue<int,vector<int>,cmp> dijQue;
memset(dis,-1,sizeof(dis));
memset(vis,0,sizeof(vis));
dijQue.push(start);
dis[start]=0;
while(!dijQue.empty()) {
int u=dijQue.top();
dijQue.pop();
vis[u]=0;
if(u==end)
break;
for(int i=0; i<edge[u].size(); i++) {
int v=edge[u][i].v;
if(dis[v]==-1 || dis[v]>dis[u]+edge[u][i].w) {
dis[v]=dis[u]+edge[u][i].w;
if(!vis[v]) {
vis[v]=true;
dijQue.push(v);
}
}
}
}
return dis[end];
}
int main()
{
int a,b;
scanf("%d%d",&a,&b);
Edge Qpush;Qpush.v=1;
Qpush.w=a;
edge[0].push_back(Qpush);Qpush.v=2;
Qpush.w=b;
edge[1].push_back(Qpush);printf("%d",Dijkstra(0,2));
return 0;
}
``` -
-12018-11-07 14:29:03@
#include <iostream>
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
cout << a + b << endl;
}典型c++算法,大爱noip!
-
-12018-11-03 14:49:16@
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<cstdlib>
using namespace std;
long long l,s,t,m;
long long map[1000005];
long long k[1000005];
long long pos[105];
long long ans[1000005];
long long min(long long x,long long y)
{
if(x<y)return x;
return y;
}
int main()
{
for(int i=0;i<=1000004;i++)
ans[i]=99999999;
scanf("%I64d%I64d%I64d%I64d",&l,&s,&t,&m);
long long mod=s*t;
for(int i=1;i<=m;i++)
scanf("%I64d",&pos[i]);
sort(pos+1,pos+m+1);
int temp=0;
for(int i=1;i<=m;i++)
{
long long cha=pos[i]-pos[i-1];
long long qwe=cha;
cha%=mod; qwe/=mod;
temp+=cha;
if(qwe!=0)
temp+=mod;
k[temp]=1;
}
temp+=s*t;
if(s==t)
{
long long u=0;long long v=s;int an=0;
while(u<=temp)
{
u+=v;
if(k[u])an++;
}
printf("%d",an);
exit(0);
}
for(int i=0;i<=s-1;i++)
ans[i]=0;
for(int i=s;i<=temp;i++)
{
for(int j=s;j<=t;j++)
{
if(i-j<0)break;
if(i-j>0&&i-j<s)continue;
ans[i]=min(ans[i-j]+k[i],ans[i]);
}
}
printf("%I64d",ans[temp]);
} -
-12018-10-19 19:13:41@
#include<iostream>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
cout<<a+b<<endl;
return 0;
}
C++谢谢 -
-12018-09-30 18:31:30@
重载运算符
#include<iostream>
using namespace std;
struct p1000
{
int num;
int operator +(p1000 x)
{return x.num+num;}
}a,b;
int main()
{
cin>>a.num>>b.num;
cout<<a+b;
return 0;
} -
-12018-08-25 19:38:21@
C++算法
1. #include<iostream>
2. using namespace std;
3. int main(){
4. int x,y;
5. cin>>x>>y;
6. return 0;
5. } -
-12018-08-22 11:25:19@
最标准的C:
#include<iostream> #inckude<cstdio> using namespace std; int main() { int a,b,c; cin>>a>>b; c=a+b; std::cout<<c; return 0; }
信息
- ID
- 1000
- 难度
- 9
- 分类
- (无)
- 标签
- (无)
- 递交数
- 73504
- 已通过
- 28192
- 通过率
- 38%
- 被复制
- 201