跳到正文

#SUSPENDED#

1656953

数学何意味DP何意味STL何意味图论何意味出生CCF何意味OI何意味。我背包DP和中位数代码呢。Devc++还我命来!Devc++还我命来!

在洛谷打开
资料、奖项与版本

资料

编号
1656953
抓取

陶片放逐

− 进入主站

查看记录

13389232511

今日看猴 be like: https://www.luogu.com.cn/ticket/FRCK444137

C++
#include <bits/stdc++.h>
#define int long long
using namespace std;

int n,m,a[1000005],maxn,ans;
int da[1000005],sda[1000005];

struct node
{
	int c,l,r;
};
node q[1000005];

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    ans = m;
    for (int i = 1;i <= n;i++)
	    cin >> a[i];
    for (int i = 1;i <= m;i++)
	{
	    cin >> q[i].c >> q[i].l >> q[i].r;
	    maxn = max(maxn,q[i].r);
	    da[q[i].l] += q[i].r;
	    da[q[i].r + 1] -= q[i].r;
	}
    for (int i = 1;i <= maxn;i++)
	{
	    sda[i] = sda[i - 1] + da[i];
	    while (ans > 0 && sda[i] > q[i].c)
		{
		    da[q[ans].l] -= q[ans].c;
		    da[q[ans].r + 1] += q[ans].c;
		    if (q[ans].l <= i && 
					i <= q[ans].r)
				sda[i] -= q[ans].c;
		    ans--;
		}
	}
    if (ans == m) cout << "0\n";
    else
	{
	    cout << "-1\n";
	    cout << ans + 1 << "\n";
	}
    return 0;
}
C++
CF1120F

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

int n,c,d,ans,t[100005],c1[100005],h[100005];
bool f[100005];

signed main()
{
	cin >> n >> c >> d;
	for (int i = 1;i <= n;i++)
	{
		cin >> t[i];
		char c;
		cin >> c;
		f[i] = c == 'W';
	}
	ans = d * n;
	cin >> t[n + 1];
	f[n + 1] = !f[n];
	int lst = t[n + 1],c1 = 0;
	for (int i = n;i >= 1;i--)
	{
		if (f[i] == f[i + 1]) c1 += min(d,(lst - t[i + 1]) * c);
		else lst = t[i + 1];
		ans = min(ans,(t[n + 1] - t[i]) * c + c1 + d * (i - 1));
	}
	cout << ans << "\n";
	return 0;
}
C++
CF508E

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

int n,a[605],b[605],c[605],p;
bool f = 1;
stack<int> s;
char ch[1205];

int main()
{
	cin >> n;
	for (int i = 1;i <= n;i++) cin >> a[i] >> b[i];
	for (int i = 1;i <= n;i++)
	{
		s.push(i);
		c[i] = p;
		ch[++p] = '(';
		while (!s.empty())
		{
			if (b[s.top()] + c[s.top()] < p)
			{
				f = 0;
				break;
			}
			if (a[s.top()] + c[s.top()] > p)
			{
				break;
			}
			ch[++p] = ')';
			s.pop();
		}
		if (!f) break;
	}
	if (!f || p != n * 2)
	{
		cout << "IMPOSSIBLE\n";
		return 0;
	}
	for (int i = 1;i <= p;i++) cout << ch[i];
	return 0;
}
C++
P5550

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

int n,m,s,k;

struct mat
{
	int n,m,a[105][105];
	void clear()
	{
		n = m = 0;
		memset(a,0,sizeof a);
	}
	void print()
	{
		for (int i = 1;i <= n;i++)
		{
			for (int j = 1;j <= m;j++) cout << a[i][j] << " ";
			cout << "\n";
		}
	}
	mat operator*(const mat &other) const
	{
		mat t;
		t.clear();
		t.n = n,t.m = other.m;
		for (int i = 1;i <= n;i++)
		{
			for (int j = 1;j <= n;j++)
			{
				for (int k = 1;k <= n;k++)
				{
					t.a[i][j] += a[i][k] * other.a[k][j];
				}
			}
		}
		return t;
	}
};


mat p(mat b,int other)
{
	mat t;
	t.clear();
	t.n = t.m = n;
	for (int i = 1;i <= n;i++) t.a[i][i] = 1;
	while (other)
	{
		if (other & 1) t = t * b;
		b = b * b;
		other >>= 1;
	}
	return t;
}

signed main()
{
	cin >> n >> s >> m >> k;
	mat a,c;
	for (int i = 1;i <= n;i++)
	{
		cin >> c.a[1][i];
		a.a[i % n + 1][i] = 1;
	}
	swap(a.a[s],a.a[m]);
	c = c * p(a,k);
	for (int i = 1;i <= n;i++)
	{
		cout << c.a[1][i] << " ";
	}
	return 0;
}
C++
#include<bits/stdc++.h>
#define ll long long
#define inf 0x7f7f7f7f
using namespace std;
int read()
{
	int x = 0, f = 1; char ch = getchar();
	while( ch < '0' || ch > '9') { if(ch == '-') f = -1; ch = getchar(); }
	while( ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x*f;
}
const int N = 105;
ll a[N],b[N];
void exgcd(ll n,ll m,ll &x,ll &y)
{
	if(!m)
	{
		x = 1; y = 0;
		return ;
	}
	exgcd(m, n%m, x, y);
	ll t = x;
	x = y;
	y = t - n/m*y;
}
ll gcd(ll n,ll m)
{
	return m==0?n:gcd(m, n%m);
}
ll inv(ll n,ll p)
{
	ll x,y;
	exgcd(n,p,x,y);
	return (x + p) % p;
}
ll qp(ll x,ll t,ll p)
{
	ll ans = 1;
	while(t)
	{
		if(t&1) ans = ans * x % p;
		x = x*x % p;
		t >>= 1;
	}
	return ans;
}
ll F(ll n,ll p,ll pk) //n!在模p^k意义下不含p因子的结果 
{
	if(n == 0) return 1;
	ll rou = 1; // 1~p^k 中所有不为p倍数的值 
	ll res = 1; // p^k ~n 中所有不为p倍数的值 
    for(ll i = 1; i <= pk; i++)
	{	
        if(i%p != 0) 
			rou = rou * i % pk;
    }
    rou = qp(rou, n/pk, pk); 
    for(ll i = pk*(n/pk) ;i <= n;i++)
	{
        if(i%p != 0) 
			res = res * (i%pk) % pk;
    }
    return F(n/p, p, pk) * rou % pk * res % pk;	//迭代处理含有p因子的情况 
}
ll G(ll n,ll p) // n!中含有多少p的因子 
{ // n = 10, p = 3 : 3,6,9->3
	if(n < p) return 0;
	return n/p + G(n/p, p);
}
ll C_p(ll n,ll m, ll p, ll pk) // C(n,m) % p^k
{
	ll n_p = F(n, p, pk); // n! % p^k
	ll m_p = inv(F(m, p, pk), pk); // m! % p^k 
	ll nm_p = inv(F(n-m, p, pk), pk); // (n-m)! % p^k
	ll p_nm = qp(p, G(n, p) - G(m, p) - G(n-m, p), pk); // p^(g(n) - g(m) - g(n-m))
	return n_p * m_p % pk * nm_p % pk * p_nm % pk;
}
ll exLucas(ll n,ll m,ll p)
{
	int cnt = 0;
	ll tmp = p;
	for(int i = 2;1LL*i*i <= tmp;i++) //枚举p所有因数 
	{
		if(tmp % i == 0)
		{ 
			cnt++; a[cnt] = 1;
			while(tmp%i == 0)
			{
				a[cnt] *= i; //p^k 
				tmp /= i; 
			}
			b[cnt] = C_p(n, m, i, a[cnt]); // C(n,m) % p^k   i:p
		}
	}
	if(tmp != 1)
	{
		a[++cnt] = tmp;
		b[cnt] = C_p(n, m, tmp, tmp);
	}
	ll ans = 0;
	for(int i = 1;i <= cnt;i++)
	{
		ll M = p/a[i]; // p 原始模数 
		ll invM = inv(M, a[i]);  // M % a[i] 逆元 
		ans = (ans + b[i]*M % p * invM % p) % p;
	}
	return ans;
}
int main()
{
	ll n,m,p;
	cin >> n >> m >> p;
	cout << exLucas(n, m, p);
	return 0;
}
C++
#include <bits/stdc++.h>
#define int long long
using namespace std;

struct INT
{
	bool f;
	int l,a[10100];
	void init()
	{
		l = 0;
		memset(a,0,sizeof(a));
	}
	void read()
	{
		char ch = getchar();
		while (ch < '0' || ch > '9')
		{
			if (ch == '-') f = 1;
			ch = getchar();
		}
		while (ch >= '0' && ch <= '9')
		{
			a[++l] = ch - '0';
			ch = getchar();
		}
		for (int i = 1;i * 2 <= l;i++)
		{
			swap(a[i],a[l - i + 1]);
		}
	}
	void print()
	{
		for (int i = l;i >= 1;i--) putchar(a[i] + '0');
	}
	void del0()
	{
		while (l > 1 && a[l] == 0) l--;
	}
	bool operator<(const INT &other) const
	{
		if (l > other.l) return false;
		if (l < other.l) return true;
		for (int i = l;i >= 1;i--)
		{
			if (a[i] > other.a[i]) return false;
			else if (a[i] < other.a[i]) return true;
		}
		return false;
	}
	bool operator>(const INT &other) const
	{
		if (l < other.l) return false;
		if (l > other.l) return true;
		for (int i = l;i >= 1;i--)
		{
			if (a[i] < other.a[i]) return false;
			else if (a[i] > other.a[i]) return true;
		}
		return true;
	}
	INT operator+(const INT &other) const
	{
		INT t;
		t.init();
		t.l = max(l,other.l) + 1;
		int res = 0;
		for (int i = 1;i <= t.l;i++)
		{
			t.a[i] = a[i] + other.a[i] + res;
			if (t.a[i] >= 10)
			{
				t.a[i] -= 10;
				res = 1;
			}
			else res = 0;
		}
		t.del0();
		return t;
	}
	INT operator-(const INT &other) const
	{
		INT t;
		t.l = l;
		int res = 0;
		for (int i = 1;i <= t.l;i++)
		{
			t.a[i] = a[i] - other.a[i] + res;
			if (t.a[i] < 0)
			{
				t.a[i] += 10;
				res = -1;
			}
			else res = 0;
		}
		t.del0();
		return t;
	}
	INT operator*(const INT &other) const
	{
		INT t;
		t.init();
		t.l = l + other.l + 1;
		for (int i = 1;i <= l;i++)
		{
			int res = 0;
			for (int j = 1;j <= other.l;j++)
			{
				t.a[i + j - 1] += a[i] * other.a[j] + res;
				res = t.a[i + j - 1] / 10;
				t.a[i + j - 1] %= 10;
			}
			t.a[i + other.l] += res;
		}
		int res = 0;
		for (int i = 1;i <= t.l;i++)
		{
			t.a[i] += res;
			res = t.a[i] / 10;
			t.a[i] %= 10;
		}
		t.del0();
		return t;
	}
	INT operator/(const int &x) const
	{
		INT t;
		t.init();
		t.l = l;
		int res = 0;
		for (int i = l;i >= 1;i--)
		{
			res = res * 10 + a[i];
			t.a[i] = res / x;
			res = res % x;
		}
		t.del0();
		return t;
	}
};

signed main()
{
	INT a,b,c;
	a.read(),b.read();
	c = ;
	c.print();
	return 0;
}
C++
#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int mod = 1e9 + 7;
int fact[100005],inv[100005],ans;
ll n,s,f[25];

ll c(int n,int m)
{
	return 1ll * fact[n] * inv[m] % mod * inv[n - m] % mod;
}

void dfs(int step,int c1)
{
	if (s < 0) return ;
	if (step > n)
	{
		ans = (ans + c1 * c(s + n - 1,n - 1) + mod) % mod;
		return ;
	}
	dfs(step + 1,c1);
	s -= f[step] + 1;
	dfs(step + 1,-c1);
	s += f[step] + 1;
}

int main()
{
	cin >> n >> s;
	fact[0] = fact[1] = inv[0] = inv[1] = 1;
	for (int i = 1;i <= n;i++) cin >> f[i];
	for (int i = 2;i <= 100001;i++)
	{
		fact[i] = 1ll * fact[i - 1] * i % mod;
		inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
	}
	for (int i = 1;i <= 100001;i++)
	{
		inv[i] = 1ll * inv[i - 1] * inv[i] % mod;
	}
	dfs(1,1);
	cout << ans << "\n";
	return 0;
}

还没有收录这位用户的文章。