Panasonic Programming Contest (AtCoder Beginner Contest 195)
B - Many Oranges
最小为mi=(w+b-1)/b
最大直接让mi自增倒不符和为止,即w>mab||w<maa
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
using namespace std;
#define int long long
typedef long long LL;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int inf = 1e18;
const int mod = 998244353;
//const int mod = 1e9 + 7;
const int maxn = 3e5 + 10;
const int N = 25e5 + 100;
//int a[maxn];
void solve() {
int a,b,w;
cin>>a>>b>>w;
w*=1000;
int ma=(w+b-1)/b;
int f=0;
int mi=ma;
while (1){
if (w>ma*b||w<ma*a)break;
ma++;
f=1;
// cout<<ma*b<<" "<<ma*a<<"\n";
}
if (w>ma*b||w<ma*a)ma--;
if (f) cout<<mi<<" "<<ma<<"\n";
else cout<<"UNSATISFIABLE\n";
}
signed main() {
// ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1;
// cin >> _;
while (_--) {
solve();
}
return 0;
}
// 0 -1 4 -3 5 -3
// 0 2 -8 -11
//
C - Comma
大于999的数,他在最低位的那个逗号数量=本身-999
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
using namespace std;
#define int long long
typedef long long LL;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int inf = 1e18;
const int mod = 998244353;
//const int mod = 1e9 + 7;
const int maxn = 3e5 + 10;
const int N = 25e5 + 100;
//int a[maxn];
void solve() {
int n;
cin>>n;
int ans=0;
int sum=999;
while (n>=sum){
ans+=n-sum;
sum=sum*1000+999;
}
cout<<ans;
}
signed main() {
// ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1;
// cin >> _;
while (_--) {
solve();
}
return 0;
}
// 10101
// 10101-999
//
D - Shipping Center
贪心
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
using namespace std;
#define int long long
typedef long long LL;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int inf = 1e18;
const int mod = 998244353;
//const int mod = 1e9 + 7;
const int maxn = 1e2 + 10;
const int N = 25e5 + 100;
struct no{
int w,v;
bool operator < (const no & a){
return v>a.v;
}
}b[maxn];
int x[maxn],c[maxn];
int vis[maxn];
void solve() {
int n,m,q;
cin>>n>>m>>q;
for (int i = 1; i <=n; ++i) cin>>b[i].w>>b[i].v;
for (int i = 1; i <=m; ++i) cin>>x[i];
sort(b+1,b+1+n);
int l,r;
while (q--){
cin>>l>>r;
int top=0,ans=0;
for (int i = 1; i <=m; ++i) {
if (i<l||i>r) c[++top]=x[i];
vis[i]=0;
}
sort(c+1,c+top+1);
for (int i = 1; i <=n; ++i) {
for (int j = 1; j <=top; ++j) {
if (!vis[j]&&c[j]>=b[i].w) {
ans+=b[i].v;
vis[j]=1;
break;
}
}
}
cout<<ans;
cout<<"\n";
}
}
signed main() {
// ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1;
// cin >> _;
while (_--) {
solve();
}
return 0;
}
// 10101
// 10101-999
//
E - Lucky 7 Battle
记忆化搜索/dp
dp[i][j]:第i回合,目前mod7=j,能否保证mod7=0;
对于i , 有j10%7和(j10+s[i]-‘0’)%7
x[i]为T只要有一个满足=0
若为A则都要满足
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
using namespace std;
#define int long long
typedef long long LL;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int inf = 1e18;
const int mod = 998244353;
//const int mod = 1e9 + 7;
const int maxn = 2e5 + 10;
const int N = 25e5 + 100;
int dp[maxn][7];
int n;
string s,x;
void solve() {
cin>>n>>s>>x;
dp[n][0]=1;
for (int i = n-1; i >=0 ; --i) {
for (int j = 0; j < 7; ++j) {
bool p=dp[i+1][10*j%7],q=dp[i+1][(10*j+s[i]-'0')%7];
dp[i][j]=x[i]=='T'?p|q:p&q;
}
}
cout<<(dp[0][0]?"Takahashi":"Aoki");
}
signed main() {
// ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1;
// cin >> _;
while (_--) {
solve();
}
return 0;
}
// 10101
// 10101-999
//
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
using namespace std;
#define int long long
typedef long long LL;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int inf = 1e18;
const int mod = 998244353;
//const int mod = 1e9 + 7;
const int maxn = 2e5 + 10;
const int N = 25e5 + 100;
int dp[maxn][7];
int n;
string s,x;
int dfs(int i,int j){
if (i==n) return (j==0);
if (~dp[i][j]) return dp[i][j];
if (x[i]=='T')
dp[i][j]=dfs(i+1,j*10%7)|dfs(i+1,(j*10+s[i]-'0')%7);
else dp[i][j]=dfs(i+1,j*10%7)&dfs(i+1,(j*10+s[i]-'0')%7);
return dp[i][j];
}
void solve() {
memset(dp,-1,sizeof(dp));
cin>>n>>s>>x;
if (dfs(0,0)) cout<<"Takahashi";
else cout<<"Aoki";
cout<<"\n";
}
signed main() {
// ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1;
// cin >> _;
while (_--) {
solve();
}
return 0;
}
// 10101
// 10101-999
//
F - Coprime Present
dp
空集时为1
res记录了i的质因子,若!(res&j)即i与j这个状态没有相交的质因子
就可以把j状态选的质因子的方案数加到res|j这个状态上
ans=每个状方案数之和
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
using namespace std;
#define int long long
typedef long long LL;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int inf = 1e18;
const int mod = 998244353;
//const int mod = 1e9 + 7;
const int maxn = 2e5 + 10;
const int N = 25e5 + 100;
int dp[1<<20];
int p[20]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71};
void solve() {
int a,b;
cin>>a>>b;
dp[0]=1;
for (int i = a; i <=b; ++i) {
int res=0;
for (int j = 0; j < 20; ++j) {
if (i%p[j]==0) res|=1<<j;
}
for (int j = 0; j < 1 << 20; ++j) {
if (!(res&j)){
dp[j|res]+=dp[j];
}
}
}
int ans=0;
for (int k = 0; k < 1 << 20; ++k) {
ans+=dp[k];
}
cout<<ans<<"\n";
}
signed main() {
// ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1;
// cin >> _;
while (_--) {
solve();
}
return 0;
}