@baobaobear
2020-03-15T11:07:50.000000Z
字数 7396
阅读 173
contest
#include<iostream>
#include<stack>
#include<cstdio>
#include<map>
#include<set>
#include<queue>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
#define me(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
const int N=500005;
const int M=200005;
int main()
{
int n,d;
cin>>n>>d;
int q=2*d+1;
if(n%q==0)cout<<n/q<<endl;
else cout<<n/q+1<<endl;
return 0;
}
#include<set>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<string>
#include<vector>
#include<climits>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define endl '\n'
#define rtl rt<<1
#define rtr rt<<1|1
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define maxx(a, b) (a > b ? a : b)
#define minn(a, b) (a < b ? a : b)
#define zero(a) memset(a, 0, sizeof(a))
#define INF(a) memset(a, 0x3f, sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define _test printf("==================================================\n")
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> P2;
const double pi = acos(-1.0);
const double eps = 1e-7;
const ll MOD = 1000000007LL;
const int INF = 0x3f3f3f3f;
const int _NAN = -0x3f3f3f3f;
const double EULC = 0.5772156649015328;
const int NIL = -1;
template<typename T> void read(T &x){
x = 0;char ch = getchar();ll f = 1;
while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
const int maxn = 1e4+10;
ll arr[maxn];
int main(void) {
ll l, r;
while(~scanf("%lld%lld", &l, &r)) {
if (l>r) swap(l, r);
int kase = 0;
for (ll i = l; i<=r && i<=l+10000LL; ++i, ++kase)
arr[kase] = i%2019LL;
sort(arr, arr+kase);
int pos = unique(arr, arr+kase)-arr;
ll ans = INF;
for (int i = 0; i<pos; ++i)
for (int j = i+1; j<pos; ++j)
ans = min(ans, arr[i]*arr[j]%2019);
printf("%lld\n", ans);
}
return 0;
}
#include <iostream>
#define int long long
using namespace std;
int a[500010], n;
signed main() {
ios::sync_with_stdio(0);
cin.tie(NULL);
cin >> n;
for(int i = 1; i <= n; ++i) {
cin >> a[i];
}
int last = 0;
for(int i = 1; i <= n; i += 2) {
last += a[i];
}
for(int i = 2; i <= n; i += 2) {
last -= a[i];
}
cout << last;
for(int i = 2; i <= n; ++i) {
cout << ' ' << (last = a[i - 1] * 2 - last);
}
return 0;
}
#include<iostream>
#include<set>
#include<string.h>
#include<cmath>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
ll r, b, x, y;
ll get(ll m)
{
ll k = r - m;
ll z = b - y * m;
return m + min(z, k / x);
}
ll bitfound(ll l, ll r)
{
while(l < r - 1)
{
ll mid = (l + r) / 2;
ll mmid = (mid + r) / 2;
if( get(mid) > get(mmid))
r = mmid;
else
l = mid;
}
return max(get(l), get(r));
}
signed main(){
while (~scanf("%lld%lld%lld%lld", &r, &b, &x, &y))
{
//if (b >= r * y)
// printf("%lld\n", r);
//else if (r >= b * x)
// printf("%lld\n", b);
//else
//{
printf("%lld\n", bitfound(0, min(b / y, r)));
//}
}
}
//https://www.cnblogs.com/shuitiangong/
#include<set>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<string>
#include<vector>
#include<climits>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define endl '\n'
#define rtl rt<<1
#define rtr rt<<1|1
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define maxx(a, b) (a > b ? a : b)
#define minn(a, b) (a < b ? a : b)
#define zero(a) memset(a, 0, sizeof(a))
#define INF(a) memset(a, 0x3f, sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define _test printf("==================================================\n")
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> P2;
const double pi = acos(-1.0);
const double eps = 1e-7;
const ll MOD = 1000000007LL;
const int INF = 0x3f3f3f3f;
const int _NAN = -0x3f3f3f3f;
const double EULC = 0.5772156649015328;
const int NIL = -1;
template<typename T> void read(T &x){
x = 0;char ch = getchar();ll f = 1;
while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
const int maxn = 1e2+10;
bool vis[maxn];
int n, d, ans;
void dfs(int p, int st, int sum) {
if (p==n) {
if (sum == d) ++ans;
return;
}
for (int i = st; i<10; ++i) {
if (sum+i > d) break;
if (!vis[i]) {
vis[i] = true;
dfs(p+1, i+1, sum+i);
vis[i] = false;
}
}
}
int main(void) {
while(~scanf("%d%d", &n, &d) && (n||d)) {
ans = 0;
dfs(0, 0, 0);
printf("%d\n", ans);
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int a[100005];
int main() {
int n,p,k = 0,tmp;
cin >> n;
while (n--){
cin >> p;
tmp = upper_bound(a,a + k,p,greater< int >()) - a;
if (tmp == k){
a[k] = p;
++ k;
}
else a[tmp] = p;
}
cout << k << endl;
}
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main()
{
int l, k;
LL dp[105][2] = {1}, sum=0;
cin >> l >> k;
for (int i = 1; i <= l; i++){
dp[i][0] = dp[i - 1][1];
dp[i][1] = dp[i - 1][0];
if (i >= k) dp[i][1] += dp[i - k][0];
}
for (int i = 1; i <= l; i++) sum += dp[i][1];
cout << sum << endl;
}
#include<iostream>
#include<set>
#include<string.h>
#include<cmath>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
/*
struct edge{
int to, next;
}e[200005];
int head[100005], tot, n, k, x, y, mod = 1000000007;
void add(int u, int v)
{
e[tot].to = v, e[tot].next = head[u], head[u] = tot++;
}
int trie[700005][26], tot = 1, mark[700005], gt[258], num;
char str[16000005];
void insert(char *s, int rt, int k)
{
for (int i = 0; i < k; i++)
{
int x = gt[s[i]];
if (trie[rt][x] == 0)
{
trie[rt][x] = ++tot;
}
rt = trie[rt][x];
}
mark[rt] = 1;
}
int n, m;
signed main(){
scanf("%d%d", &n, &m);
scanf("%s", str);
int len = strlen(str), ans = 0;
for (int i = 0; i < len; i++) gt[str[i]] = 1;
for (int i = 0; i <= 256; i++)
if (gt[i]) gt[i] = num++;
for (int i = 0; i <= len - n; i++)
insert(str + i, 1, n);
for (int i = 0; i <= tot; i++) ans += mark[i];
printf("%d\n", ans);
}*/
typedef unsigned long long ull;
ull base=131;
ull a[16000010];
char str[16000010];
int n,ans=1,k;
int prime=233317;
ull mod=212370440130137957ll;
ull hashe(char s[])
{
int len=n;
ull ans=0;
for (int i=0;i<len;i++)
ans=(ans*base+(ull)s[i])%mod+prime;
return ans;
}
int main()
{
scanf("%d%d",&n, &k);
scanf("%s",str);
int len = strlen(str);
for(int i=0;i<= len - n;i++)
{
a[i] = hashe(str + i);
}
sort(a, a + len - n + 1);
for(int i=0;i<len - n;i++)
{
if(a[i]!=a[i+1])
ans++;
}
printf("%d",ans);
}
#include<iostream>
#include<set>
#include<string.h>
#include<cmath>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
struct edge{
int to, next;
}e[200005];
int head[100005], tot, n, k, x, y, mod = 1000000007;
ll ans;
void add(int u, int v)
{
e[tot].to = v, e[tot].next = head[u], head[u] = tot++;
}
void dfs(int x, int fa, int dep)
{
int num = 0;
for (int u = head[x]; ~u; u = e[u].next)
{
int v = e[u].to;
if (v == fa) continue;
dfs(v, x, dep + 1);
if (dep == 0)
{
ans = ans * (k - num - 1) % mod;
if (k - num - 1 <= 0) ans = 0;
}
else
{
ans = ans * (k - num - 2) % mod;
if (k - num - 2 <= 0) ans = 0;
}
num++;
}
}
signed main(){
while (~scanf("%d%d", &n, &k))
{
ans = k;
memset(head, -1, sizeof(head));
for (int i = 0; i < n - 1; i++)
{
scanf("%d%d", &x, &y);
add(x, y), add(y, x);
}
dfs(1, -1, 0);
printf("%lld\n", ans);
}
}
#include<iostream>
#include<set>
#include<string.h>
#include<cmath>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
/*
struct edge{
int to, next;
}e[200005];
int head[100005], tot, n, k, x, y, mod = 1000000007;
void add(int u, int v)
{
e[tot].to = v, e[tot].next = head[u], head[u] = tot++;
} */
vector<P> gt[305];
int mod = 1000000007, dp[305][305][305], n, m, ans;
bool judge(int a, int b, int c, int r)
{
for (int i = 0; i < gt[r].size(); i++)
{
int ct = 0;
if (a >= gt[r][i].first)
ct++;
if (b >= gt[r][i].first)
ct++;
if (c >= gt[r][i].first)
ct++;
if (ct != gt[r][i].second)
return false;
}
return true;
}
signed main(){
while (~scanf("%d%d", &n, &m))
{
for (int i = 0; i <= 300; i++) gt[i].clear();
ans = 0;
for (int i = 0; i < m; i++)
{
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
gt[b].push_back(P(a, c));
}
memset(dp, 0, sizeof(dp));
dp[0][0][0] = 1;
for (int i = 0; i <= n; i++)
{
for (int j = 0; j <= n; j++)
{
for (int k = 0; k <= n; k++)
{
int x = max(i, max(j, k)) + 1;
if (judge(i, j, k, x - 1) && dp[i][j][k])
{
dp[x][j][k] = (dp[x][j][k] + dp[i][j][k]) % mod;
dp[i][x][k] = (dp[i][x][k] + dp[i][j][k]) % mod;
dp[i][j][x] = (dp[i][j][x] + dp[i][j][k]) % mod;
}
else
{
dp[i][j][k] = 0;
}
if (x == n + 1) ans = (ans + dp[i][j][k]) % mod;
}
}
}
printf("%d\n", ans);
}
}