<=n/4;k++){for(int p=0;p<=n/4;p++){h=i+j+k+p;if(i){dp[i][j][k][p]=max(dp[i][j][k][p],dp[i-1][j][k][p]+a[h][1]);}if(j){dp[i][j][k][p]=max(dp[i][j][k][p],dp[i][j-1][k][p]+a[h][2]);}if(k){dp[i][j][k][p]=max(dp[i][j][k][p],dp[i][j][k-1][p]+a[h][3]);}if(p){dp[i][j][k][p]=max(dp[i][j][k][p],dp[i][j][k][p-1]+a[h][4]);}}}}}cout<
F 坐火车 (最短路改编)不是很懂,老是卡在9分!!!
最好从头开始学一遍最短路!!!
推荐链式前向星优化:算法小讲堂之最短路算法(Floyd++SPFA+)
关键是考虑如何求经过城市的数量的最小值!
#include#include#include#define int long longusing namespace std;typedef pair PII;const int N=1e5+10;const int M=4*N;const int inf=0x3f3f3f3f;int n,m;int h[N],e[M],ne[M],w[M],idx;int dist[N];int cnt[N];bool vis[N];void init(){memset(dist,inf,sizeof(dist));memset(cnt,inf,sizeof(cnt));memset(h,-1,sizeof(h));cnt[1]=1;dist[1]=0;}void add(int a,int b,int c){e[idx]=b;w[idx]=c;ne[idx]=h[a];h[a]=idx++;}void dij(){priority_queue,greater > q;q.push({0,1});while(q.size()){PII t=q.top();q.pop();int ver=t.second;if(vis[ver]){continue;} vis[ver]=1;for(int i=h[ver];i!=-1;i=ne[i]){int j=e[i];if(cnt[j]>cnt[ver]+1){cnt[j]=cnt[ver]+1;dist[j]=dist[ver]+w[i];q.push({cnt[j],j});}else if(cnt[j]==cnt[ver]+1){if(dist[j]>dist[ver]+w[i]){dist[j]=dist[ver]+w[i];q.push({cnt[j],j});}}}}}signed main(){cin>>n>>m;init();while(m--){int a,b,c;cin>>a>>b>>c;add(a,b,c);add(b,a,c);}dij();cout<
9分代码:啊啊啊啊——
#include#include#include#define int long longusing namespace std;const int inf=0x3f3f3f3f;const int N=100005;const int M=4*N;int n,m,cnt;int head[N],dis[N],sum[N];bool vis[N];typedef pairPll;struct Edge{int next;int to;int w;}edge[M];void init(){memset(vis,0,sizeof(vis));memset(dis,inf,sizeof(dis));memset(head,-1,sizeof(head));memset(sum,inf,sizeof(sum));cnt=0;dis[1]=0;sum[1]=1;}void add(int u,int v,int w){edge[cnt].to=v;edge[cnt].w=w;edge[cnt].next=head[u];head[u]=cnt++;}void dij(){priority_queue,greater > q;q.push(Pll(0,1));Pll temp;while(!q.empty()){temp=q.top();q.pop();int u=temp.second;if(vis[u]){continue;}vis[u]=1;int t,len;for(int i=head[u];i!=-1;i=edge[i].next){t=edge[i].to;len=edge[i].w;if(sum[t]>sum[u]+1){sum[t]=sum[u]+1;dis[t]=dis[u]+len;q.push(Pll(dis[t],t)); }else if(sum[t]==sum[u]+1){if(dis[t]>dis[u]+len){dis[t]=dis[u]+len;}}}}}signed main(){init();cin>>n>>m;int u,v,w;for(int i=1;i<=m;i++){cin>>u>>v>>w;add(u,v,w);add(v,u,w);}dij();cout<
G A Xor Bagain 位运算问题,不懂!!!
学习位运算~~~
#include#define int long longusing namespace std;const int N=300005;int n,pre[N],a[N];signed main(){cin>>n;for(int i=1;i<=n;i++){cin>>a[i];pre[a[i]]++;//记录每一个数出现的次数}//枚举每一个位数(变成二进制之后)for(int i=0;i<18;i++){//二进制枚举每(1-1e5)for(int j=0;j<262144;j++){// 如果这个数与这个二进制数一样那么if(j&(1<
H摘苹果
思路:正常思路,模拟,玄学问题,g++编译器超时,clang++编译器能过
可以考虑其他做法进行时间优化!!!
#include#include#define int long longusing namespace std;const int N=100005;int a[N];signed main(){int n,m;cin>>n>>m;for(int i=1;i<=n;i++){scanf("%lld",&a[i]);}while(m--){int op,l,r,ans;scanf("%lld%lld%lld",&op,&l,&r);if(op==1){for(int i=l;i<=r;i++){if(a[i]>=10){a[i]-=((a[i]-1)/3+1);}}}if(op==2){ans=0;for(int i=l;i<=r;i++){if(a[i]<100){ans++;}}printf("%lld\n",ans);}if(op==3){ans=0;for(int i=l;i<=r;i++){ans+=a[i];}printf("%lld\n",ans);}}return 0;}