这一场题目出的很好
A题: Task Computing
如果我们已经选了一些物品,其权值为 x,现在我们需要往前面添加一个(w,p) 的物品。
那么我们的权值会变成 w+p · X
这种做法很像模拟经营的 前面选的会对后面产生影响
#include<bits/stdc++.h>
using namespace std;
template<class T>inline void read(T&x){//快读
char c,last=' ';
while(!isdigit(c=getchar()))last=c;
x=c^48;
while(isdigit(c=getchar()))x=(x<<3)+(x<<1)+(c^48);
if(last=='-')x=-x;
}
const int MAXN=1e5+5;
int n,m;
double dp[MAXN][25];
struct node{
int w;
double p;
}a[MAXN];
bool cmp(node a,node b){
return (1-a.p)/a.w<(1-b.p)/b.w;//注意sort时不允许有等号
}
int main()
{
read(n),read(m);
for(int i=1;i<=n;++i)read(a[i].w);
for(int i=1;i<=n;++i)cin>>a[i].p,a[i].p/=10000;
sort(a+1,a+n+1,cmp);
double ans=0;
for(int i=n;i>=1;--i){
for(int j=1;j<=min(m,n-i+1);++j){
dp[i][j]=max(dp[i+1][j],dp[i+1][j-1]*a[i].p+a[i].w);
}
}
cout<<fixed<<setprecision(12)<<dp[1][m]<<'\n';
return 0;
}
D Jobs (Easy Version)
code:
int n, q;
bitset<405>pre[11][405][405];
int solve(int a, int b, int c) {
int res = 0;
for (int id = 1; id <= n; id++) {
if (pre[id][a][b][c])res++;
}
return res;
}
ll pw[MAXN];
void slove() {
cin >> n >> q;
for (int id = 1; id <= n; id++) {
int len; cin >> len;
while (len--) {
int a, b, c; cin >> a >> b >> c;
pre[id][a][b][c] = 1;
}
for (int i = 1; i <= 400; i++) {
for (int j = 1; j <= 400; j++) {
for (int k = 1; k <= 400; k++) {
pre[id][i][j][k] = pre[id][i][j][k] | pre[id][i - 1][j][k] | pre[id][i][j - 1][k] | pre[id][i][j][k - 1];
}
}
}
}
int seed;
cin >> seed;
std::mt19937 rng(seed);
std::uniform_int_distribution<> u(1, 400);
pw[0] = 1;
for (int i = 1; i <= q; i++)(pw[i] = pw[i - 1] * seed) %= mod;
ll ans = 0;
ll lastans = 0;
for (int i = 1; i <= q; i++)
{
int IQ = (u(rng) ^ lastans) % 400 + 1; // The IQ of the i-th friend
int EQ = (u(rng) ^ lastans) % 400 + 1; // The EQ of the i-th friend
int AQ = (u(rng) ^ lastans) % 400 + 1; // The AQ of the i-th friend
lastans = solve(IQ, EQ, AQ); // The answer to the i-th friend
ans += lastans * pw[q - i];
ans %= mod;
}
cout << ans << endl;
}
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=410;
const int mod=998244353;
void sync()
{
cin.tie(0)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
}
int T;
int n,c[12][N][N];
int main()
{
sync();
cin>>n>>T;
for(int i=1;i<=n;i++)
{
int k,a,b,t;cin>>k;
for(int x=0;x<N;x++)
for(int y=0;y<N;y++)
c[i][x][y]=N;
while(k--)
{
cin>>a>>b>>t;
c[i][a][b]=min(c[i][a][b],t);
}
for(int x=1;x<N;x++)
for(int y=1;y<N;y++)
c[i][x][y]=min(c[i][x][y],min(c[i][x-1][y],c[i][x][y-1]));
}
int seed;
cin>>seed;
std::mt19937 rng(seed);
std::uniform_int_distribution<> u(1,400);
int lastans=0;
ll ans=0;
while(T--)
{
int IQ=(u(rng)^lastans)%400+1; // The IQ of the i-th friend
int EQ=(u(rng)^lastans)%400+1; // The EQ of the i-th friend
int AQ=(u(rng)^lastans)%400+1; // The AQ of the i-th friend
lastans=0;
for(int i=1;i<=n;i++)
lastans+=(c[i][IQ][EQ]<=AQ);
ans=(ans*seed+lastans)%mod;
}
cout<<ans<<'\n';
}
H Wall Builder II
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<vector>
#include<cmath>
using namespace std;
const int N=1e4+10;
int n;
int cnt[N];
vector<int>p[N];//p[i]存第i行组成的矩形宽度
bool check(int w,int h)
{
for(int i=1;i<=h;i++) p[i].clear();
for(int i=1;i<=n;i++) cnt[i]=0;
for(int i=1;i<=h;i++)
{
int t=w;
for(int j=n;j>=1;j--)
{
while(cnt[j]<n+1-j&&t>=j)
{
p[i].push_back(j);
cnt[j]++;
t-=j;
}
if(!t) break;
}
if(t) return false;
}
return true;
}
int main()
{
int T;
cin>>T;
while(T--)
{
scanf("%d",&n);
long long ans=0;
for(int i=1;i<=n;i++)
ans+=i*(n+1-i);
for(int i=(int)sqrt(ans);i<=ans;i++)
{
if(ans/i*i!=ans) continue;
if(check(i,ans/i))
{
printf("%d\n",(i+ans/i)*2);
for(int j=ans/i;j>=1;j--)
{
int t=0;
for(int k=0;k<p[j].size();k++)
{
printf("%d %d %d %d\n",t,j-1,t+p[j][k],j);
t+=p[j][k];
}
}
break;
}
}
}
return 0;
}
K NIO's Sword
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<vector>
#include<cmath>
using namespace std;
const int N=1e6+10;
int p10[15]={1,10,100,1000,10000,100000,1000000,10000000};
int cnt(long long x)
{
int ans=0;
while(x)
{
ans++;
x/=10;
}
return ans;
}
int main()
{
int n;
cin>>n;
if(n==1)
{
printf("0");
return 0;
}
int ans=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=6;j++)
{
long long x=((i+1-1ll*i*p10[j])%n+n)%n;
if(cnt(x)<=j)
{
ans+=j;
break;
}
}
}
printf("%d",ans);
return 0;
}
A Particle Arts
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<vector>
#include<cmath>
using namespace std;
const int N=1e5+10;
int cnt[200];
long long a[N],b[N];
int main()
{
long long n;
cin>>n;
for(int i=1;i<=n;i++)
{
int t;
scanf("%lld",&a[i]);
for(int j=0;j<15;j++)
cnt[j]+=(a[i]>>j&1);
}
__int128 ans=0,ans1=0;
for(int i=1;i<=n;i++)
{
for(int j=0;j<15;j++)
if(cnt[j])
{
b[i]|=(1<<j);
cnt[j]--;
}
ans+=b[i];
ans1+=b[i]*b[i];
}
__int128 anss=ans1*n+ans*ans-2*ans*ans;
__int128 t=__gcd(anss,(__int128)n*n);
long long up = anss/t;
long long down = n*n/t;
printf("%lld/%lld",up,down);
return 0;
}