Week Of Code 28

A.Boat Trips(水)

题目大意：

n条旅游线路，每条旅游线路 pi$p_i$人。现在有m条船，每条船装c个人，问是否这些船能满足所有的旅游线路？

题目分析：

#include <bits/stdc++.h>
using namespace std;

#define RE(x) freopen(x,"r",stdin)
#define WR(x) freopen(x,"w",stdout)
#define ms(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define eps 1e-8

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<ll> vl;

const int M = 1e9 + 7;
const double PI = acos(-1.0);

const int MAXN = 1e5;
const int MAXM = 1e6;

int main() {
//RE("in.txt");WR("out.txt");
int n,c,m,p;
cin>>n>>c>>m;
string s="Yes";
while(n--) {
cin>>p;
if(c*m<p)
s="No";
}
cout<<s<<endl;
}

B.The Great XOR(位运算)

题目分析：

x=11001101

#include <bits/stdc++.h>
using namespace std;

#define RE(x) freopen(x,"r",stdin)
#define WR(x) freopen(x,"w",stdout)
#define ms(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define eps 1e-8

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<ll> vl;

const int M = 1e9 + 7;
const double PI = acos(-1.0);

const int MAXN = 1e5;
const int MAXM = 1e6;

ll q,x;
int main() {
cin>>q;
while(q--) {
cin>>x;
ll ans=0;
for(int i=0;i<35;i++) {
ll t=(1ll<<i);
if(t>=x)
break;
if(!(t&x))
ans+=(1ll<<i);
}
cout<<ans<<endl;
}
}

C.Lucky Number Eight(数位dp)

题目分析：

#include <bits/stdc++.h>
using namespace std;

#define RE(x) freopen(x,"r",stdin)
#define WR(x) freopen(x,"w",stdout)
#define ms(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define eps 1e-8

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<ll> vl;

const int M = 1e9 + 7;
const double PI = acos(-1.0);

const int MAXN = 2e5;
const int MAXM = 1e6;

int n;
char s[MAXN+5];
ll dp[MAXN+5][10];

void dfs(int pos,int mod) {
if(pos==n) {
dp[pos][mod]=(mod==0);
return;
}
else if(dp[pos][mod]!=-1)
return;
int nextmod=(mod*10+(s[pos]-'0'))%8;
dfs(pos+1,mod);
dfs(pos+1,nextmod);

dp[pos][mod]=(dp[pos+1][mod]+dp[pos+1][nextmod])%M;
}
int main() {
cin>>n;
for(int i=0;i<n;i++)
cin>>s[i];
ms(dp,-1);
dfs(0,0);
cout<<dp[0][0]-1<<endl;
}

D. The Value of Friendship(贪心算法)

题目分析：

#include <bits/stdc++.h>
using namespace std;

#define RE(x) freopen(x,"r",stdin)
#define WR(x) freopen(x,"w",stdout)
#define ms(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define eps 1e-8

#define IN "D:/water-questions/temp/input/in.txt"
#define OUT "D:/water-questions/temp/input/out.txt"

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<ll> vl;

const int M = 1e9 + 7;
const double PI = acos(-1.0);

const int MAXN = 1e5;
const int MAXM = 1e6;

int q,n,m;
int f[MAXN+5],r[MAXN+5],sum[MAXN+5];
ll ans;
int find(int x) {
return f[x]==x?x:f[x]=find(f[x]);
}
void un(int i,int j) {
int x=find(i),y=find(j);
if(x!=y) {
if(r[x]<r[y]) {
f[x]=y;
sum[y]+=sum[x];
}
else {
f[y]=x;
sum[x]+=sum[y];
if(r[x]==r[y])
r[x]++;
}
}
}
int main() {
cin>>q;
while(q--) {
cin>>n>>m;
for(int i=1;i<=n;i++) {
f[i]=i;
r[i]=1;
sum[i]=1;
}
for(int i=0;i<m;i++) {
int u,v;
cin>>u>>v;
if(find(u)!=find(v))
un(u,v);
}
vl cp;
for(int i=1;i<=n;i++)
if(f[i]==i)
cp.pb(sum[i]);
sort(cp.begin(),cp.end());

ll ans=0;
ll edge=0;
for(int i=cp.size()-1;i>=0;i--) {
edge+=(cp[i]-1);
ll temp=0;
for(int j=1;j<cp[i];j++)
temp+=(j*(j+1ll));

ans+=((m-edge)*cp[i]*(cp[i]-1)+temp);
}
cout<<ans<<endl;
}
}


• 本文已收录于以下专栏：

举报原因： 您举报文章：Week Of Code 28 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)