@baobaobear
2020-05-19T05:55:42.000000Z
字数 7219
阅读 196
contest
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<string.h>
typedef long long ll;
using namespace std;
int main()
{
double a,b;
int n;
scanf("%d",&n);
scanf("%lf %lf",&a,&b);
n-=1;
while(n--)
{
double c,d;
scanf("%lf %lf",&c,&d);
if((d/c)-(b/a)>0.05) printf("better\n");
else if((b/a)-(d/c)>0.05) printf("worse\n");
else printf("same\n");
}
return 0;
}
#include<iostream>
#include<cmath>
#include<iomanip>
#include<stack>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
int main() {
priority_queue<int> p, q;
int n, inc, dec, x, y;
long long int c = 0;
cin >> n >> inc >> dec;
while (n--) {
cin >> x >> y;
p.push(x);
q.push(y);
}
for (int i = p.size(); i > 0; i--) {
x = p.top();
y = q.top();
p.pop();
q.pop();
c += (x > y ? (dec * (x - y)) : (inc * (y - x)));
}
cout << c;
}
#include<set>
#include<map>
#include<list>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<cctype>
#include<string>
#include<vector>
#include<climits>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<sstream>
#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 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 = 5e5+10;
char str[maxn];
vector<int> num[26];
int main() {
scanf("%s", str);
int len = strlen(str);
for (int i = len-1; i>=0; --i)
num[str[i]-'a'].push_back(i);
bool flag = false;
for (int i = 0; i<len; ++i)
for (int j = 0; j<=str[i]-'a'; ++j) {
if (num[j].empty()) continue;
int tmp = num[j][0];
if (tmp>i&&j<str[i]-'a') {
swap(str[tmp], str[i]);
printf("%s\n", str);
return 0;
}
else if (tmp>i&&j==str[i]-'a') flag = true;
}
if (flag) printf("%s\n", str);
else {
swap(str[len-2], str[len-1]);
printf("%s\n", str);
}
return 0;
}
#pragma GCC optimize(2)
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue> //priority_queue<int, vector<int>, greater<int> > q;从小到大
#include <map>
#include <set> //multiset set<int,greater<int>>大到小
#include <vector>// vector<int>().swap(v);清空释放内存
#include <stack>
#include <cmath> // auto &Name : STLName Name.
#include <utility>
#include <sstream>
#include <string>//__builtin_popcount(ans);//获取某个数二进制位1的个数
#define mod 1000000007
#define mod9 998244353
typedef unsigned long long ull;
typedef long long ll;
typedef double db;
typedef long double ld;
const db eps=1e-7;
#define PII pair<int,int>
//const db pi=acos(-1);
const int INF = 0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
#define rep(i,be,en) for (int i=be;i<=en;i++)
#define per(i,be,en) for (int i=en;i>=be;i--)
using namespace std;
const int N=1e6+3;
int T,n,m,k,ans=0;
char a[N]={0};
int b[N]={0};
int main(){
scanf("%s",a+1);
n=strlen(a+1);
for(int i=1;i<=n;i++){
if(a[i]>='A'&&a[i]<='Z') ans++;
b[i]=ans;
}
int maxn=INF;
for(int i=0;i<=n;i++){
maxn=min(maxn,ans-b[i]+i-b[i]);
}
printf("%d\n",maxn);
return 0;
}
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
const int inf=0x3f3f3f3f;
int n,dp[maxn],ans=0,a[maxn];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;++i) scanf("%d",&a[i]);
for(int i=1;i<=n;++i)
{
dp[a[i]]=dp[a[i]-1]+1;
ans=max(ans,dp[a[i]]);
}
printf("%d\n",n-ans);
}
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
#include<queue>
#include<cstdio>
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
int top=0,prime[maxn],isprime[maxn],v[maxn],vis[maxn];
void Prime(int n)
{
for(int i=2;i<=n;++i)
{
if(!isprime[i]) prime[top++]=i;
for(int j=0;j<top;++j)
{
if(i*prime[j]>n) break;
isprime[i*prime[j]]=1;
if(i%prime[j]==0) break;
}
}
}
int bfs(int a,int b)
{
queue<pair<int,int> >q;
q.push({a,0});
v[a]=1;
while(!q.empty())
{
int t=q.front().first,num=q.front().second;
q.pop();
if(t==b) return num;
int t1=t/1000,t2=t/100%10,t3=t/10%10,t4=t%10;
for(int i=1;i<=9;++i)
{
if(i==t1) continue;
int x=i*1000+t2*100+t3*10+t4;
if(vis[x]&&!v[x]) q.push({x,num+1}),v[x]=1;
}
for(int i=0;i<=9;++i)
{
if(i==t2) continue;
int x=t1*1000+i*100+t3*10+t4;
if(vis[x]&&!v[x]) q.push({x,num+1}),v[x]=1;
}
for(int i=0;i<=9;++i)
{
if(i==t3) continue;
int x=t1*1000+t2*100+i*10+t4;
if(vis[x]&&!v[x]) q.push({x,num+1}),v[x]=1;
}
for(int i=0;i<=9;++i)
{
if(i==t4) continue;
int x=t1*1000+t2*100+t3*10+i;
if(vis[x]&&!v[x]) q.push({x,num+1}),v[x]=1;
}
}
return -1;
}
int main()
{
int T,a,b;
Prime(1e4);
for(int i=0;i<top&&prime[i]<1e4;++i)
if(prime[i]>=1000&&prime[i]<10000) vis[prime[i]]=1;
scanf("%d",&T);
while(T--)
{
memset(v,0,sizeof(v));
scanf("%d %d",&a,&b);
if(!vis[b]){
puts("Impossible");continue;
}
int ans=bfs(a,b);
if(ans==-1) puts("Impossible");
else printf("%d\n",ans);
}
}
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+5;
const int mod=1e9+7;
char s[maxn];
ll dp[maxn][5],ans=0;
int main()
{
scanf("%s",s+1);
int len=strlen(s+1);
dp[0][1]=dp[0][3]=1;
for(int i=1;i<=len;++i)
{
if(s[i]=='0') dp[i][1]=(dp[i-1][2]+dp[i-1][1])%mod;
if(s[i]=='1') dp[i][2]=dp[i-1][0]%mod,dp[i][3]=(dp[i-1][1]+dp[i-1][2])%mod;
if(s[i]=='2') dp[i][4]=dp[i-1][0]%mod;
if(s[i]=='*') dp[i][0]=((dp[i-1][0]+dp[i-1][3])%mod+dp[i-1][4])%mod;
if(s[i]=='?') {
dp[i][1]=(dp[i-1][2]+dp[i-1][1])%mod;
dp[i][2]=dp[i-1][0]%mod,dp[i][3]=(dp[i-1][1]+dp[i-1][2])%mod;
dp[i][4]=dp[i-1][0]%mod;
dp[i][0]=((dp[i-1][0]+dp[i-1][3])%mod+dp[i-1][4])%mod;
}
}
printf("%lld\n",((dp[len][0]+dp[len][1])%mod+dp[len][2])%mod);
}
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e3+5;
int tree[maxn*32][2],tot,ans=0,a[maxn],num[maxn*32];
void insert(int x)
{
int u=0;
for(int i=31;i>=0;--i)
{
int t=(((1LL<<i)&x)?1:0);
if(!tree[u][t]) tree[u][t]=++tot;
u=tree[u][t];
num[u]++;
}
}
void delet(int x)
{
int u=0;
for(int i=31;i>=0;--i)
{
int t=(((1LL<<i)&x)?1:0);
u=tree[u][t];
num[u]--;
}
}
int query(int x)
{
int u=0,res=0;
for(int i=31;i>=0;--i)
{
int t=(((1LL<<i)&x)?1:0);
if(tree[u][t^1]&&num[tree[u][t^1]]) u=tree[u][t^1],res+=(1LL<<i);
else u=tree[u][t];
}
return res;
}
int main()
{
int T,n;
scanf("%d",&T);
while(T--)
{
ans=tot=0;
memset(tree,0,sizeof(tree));
memset(num,0,sizeof(num));
scanf("%d",&n);
for(int i=1;i<=n;++i) scanf("%d",&a[i]),insert(a[i]);
for(int i=1;i<=n;++i)
{
delet(a[i]);
for(int j=i+1;j<=n;++j)
{
delet(a[j]);
ans=max(ans,query(a[i]+a[j]));
insert(a[j]);
}
insert(a[i]);
}
printf("%d\n",ans);
}
}
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn=1e5+5;
typedef long long ll;
const ll mod = 9937;
int pri[maxn],top = 0;
bool vis[maxn];
void prime()
{
memset(vis, 0,sizeof(vis));
for(int i = 2; i < maxn; i++)
{
if(!vis[i]) pri[top++] = i;
for(int j = 0; j < top && i * pri[j] < maxn; j++)
{
vis[i *pri[j]] = 1;
if(i % pri[j] == 0)
break;
}
}
}
ll get_phi(int x)
{
ll res = x;
int ma = sqrt(x + 0.5);
for(int i = 0; i < top && pri[i] <= ma; i++)
{
if(x % pri[i] == 0)
{
while(x % pri[i] == 0)
x /= pri[i];
res = res / pri[i] * (pri[i] - 1);
}
}
if(x > 1) res = res / x * (x - 1);
return res % mod;
}
ll quick(ll a, ll n)
{
ll res = 1;
while(n)
{
if(n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
int main()
{
ll n, m;
prime();
while(scanf("%lld%lld", &n, &m)!=EOF)
{
ll ans = 0;
int ma = sqrt(n + 0.5);
for(int i = 1; i <= ma; i++)
{
if(n % i != 0)
continue;
ans = (ans + get_phi(n / i) * quick(m, i) % mod + mod) % mod;
if(i != n / i)
ans = (ans + get_phi(i) * quick(m, n / i) % mod + mod) % mod;
}
for(ll i = 0; i < mod; i++)
if(i * n % mod == ans % mod)
{
ans = i;
break;
}
printf("%lld\n", ans);
}
return 0;
}