A.Nias and Tug-of-War
#include
#include
#include
#include
#include
using namespace std;
const int maxn = 111;
struct node
{
double x,y;
bool friend operator < (node a,node b)
{
return a.xint main()
{
int T;
scanf("%d",&T);
while(T--){
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%lf%lf",&a[i].x,&a[i].y);
sort(a+1,a+1+n);
double w1=0,w2=0;
for(int i=1;i<=n;i++){
if(i&1) w1+=a[i].y;
else w2+=a[i].y;
}
if(fabs(w1-w2)<1e-8) printf("fair\n");
else if(w1>w2) printf("red\n");
else printf("blue\n");
}
return 0;
}
B.Lowest Unique Price
平衡树维护一下最小值,配合vis数组去重并执行插入删除操作。
#include
#include
#include
#include
#include
#include
#include
using namespace std;
const int maxn=1e6+10;
int vis[maxn];
set<int>q;
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
memset(vis,0,sizeof vis);
int n;
scanf("%d",&n);
q.clear();
while(n--)
{
char s;
int x;
cin>>s;
if(s=='b'){
scanf("%d",&x);
vis[x]++;
if(vis[x]==1)
q.insert(x);
else if(vis[x]==2)
{
q.erase(x);
}
}
else if(s=='c')
{
scanf("%d",&x);
//q.erase(x);
vis[x]--;
if(vis[x]==1) q.insert(x);
else if(vis[x]==0) q.erase(x);
}
else
{
if(!q.empty()){
int tmp=*q.begin();
printf("%d\n",tmp);
}
else{
printf("none\n");
}
}
}
}
return 0;
}
C.Game!
经典对称博弈问题!
#include
#include
#include
#include
#include
using namespace std;
const int maxn = 111;
#define LL long long
int main()
{
int T;
scanf("%d",&T);
while(T--){
LL n;
scanf("%lld",&n);
if(n>=3){
printf("blankcqk\n");
}else{
printf("zbybr\n");
}
}
return 0;
}
D.Stars
E.BIGZHUGOD and His Friends I
F.BIGZHUGOD and His Friends ll
赛瓦定理,机缘巧合,不然真心不会。
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
const double eps=1e-8;
double x,y,z;
double v1,v2,v3;
int check(double a)
{
double tmp1=v1*a*v2*a*v3*a;
double tmp2=(10000.0-v1*a)*(10000.0-v2*a)*(10000.0-v3*a);
if(tmp1>tmp2) return 1;
else return 0;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
//double x,y,z;
scanf("%lf%lf%lf",&x,&y,&z);
double L=0.0,R=min(min(x,y),z);
while(R-L>=eps)
{
double mid=(L+R)/2;
double tmp=(x-mid)*(y-mid)*(z-mid)/(mid*mid*mid);
if(tmp>=1.0){
L=mid;
}
else R=mid;
}
printf("YES %.4f\n",L);
}
return 0;
}
G.Cube Number
与H类似,但是需要更复杂的处理,因为1+2与2+1,3+0的情况都需要考虑,并且素数表应该压缩,ll可使用过多,限制条件还是很多的。
比方说12,18这个样例,是有一个答案的,这个题考虑的就是这个问题,存一下这个数,再存一下这个数的另一半来计算。
#include
#include
#include
#include
//#include
//#include
//#include
//#include
using namespace std;
#define ll long long int
#define INF 0x3f3f3f3f
const int maxn = 1e6 + 10;
int n;
int ks;
int vis[maxn];
bool p[maxn];
int pri[maxn];
int sz;
void get_prim()
{
p[0] = 1; p[1] = 1;
vis[2] = 0; vis[1] = 0;
for (int i = 2; i*iif (!vis[i])
{
pri[++sz] = i;
for (int j = i * i; j <= maxn; j += i)
vis[j] = 1;
}
}
}
//function abc();
int main()
{
int T;
scanf("%d", &T);
get_prim();
while (T--) {
memset(vis, 0, sizeof vis);
scanf("%d", &n);
ll ans = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &ks);ll x = 1; ll y = 1;
int cs = 1;
int flag = 0;
while (ks >= pri[cs] && cs <= sz) {
ll tmp = pri[cs] * pri[cs] * pri[cs];
while (ks % (tmp) == 0) {
ks /= tmp;
}
if (ks % (pri[cs] * pri[cs]) == 0) {
ks /= (pri[cs] * pri[cs]);
x = x * pri[cs] * pri[cs];
y = y * pri[cs];
}
else if (ks % pri[cs] == 0) {
ks /= pri[cs];
x = x * pri[cs];
y = y * pri[cs] * pri[cs];
}
cs++;
if (y > maxn) { flag = 1; }
}
if (!flag) {
y = y * ks * ks;
if (y < maxn)
ans += vis[y];
}
x = x * ks;
vis[x]++;
}
printf("%lld\n", ans);
}
return 0;
}
//_CRT_SECURE_NO_WARNINGS
H.Square Number
感觉这个题还是有分量的。
将每一个数字里的完全平方数处理掉,然后就是看相等数字的个数了,好难想的思路。
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define ll long long int
#define INF 0x3f3f3f3f
const int maxn = 1e6 + 10;
int n;
int a[maxn];
int vis[maxn];
int p[maxn];
int pri[maxn];
int sz;
void get_prim()
{
memset(p, 0, sizeof p); sz = 0;
p[0] = 1; p[1] = 1;
for (int i = 2; i < maxn; i++) {
if (p[i] == 0) {
for (int j = 2 * i; j < maxn; j += i) {
p[j] = 1;
}
}
}
for (int i = 0; i < maxn; i++) {
if (p[i] == 0) {
pri[++sz] = i;
}
}
/*for (int i = 1; i <= 10; i++) {
printf("%d ", pri[i]);
}*/
}
int main()
{
int T;
scanf("%d", &T);
get_prim();
while (T--) {
memset(vis, 0, sizeof vis);
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
int cs = 1;
while (a[i] >= pri[cs] * pri[cs]) {
if (a[i] % (pri[cs] * pri[cs]) == 0) {
a[i] /= (pri[cs] * pri[cs]);
}
else cs++;
}
vis[a[i]]++;
}
//for (int i = 1; i <= 24; i++) printf("%d ", vis[i]);
int ans = 0;
for (int i = 1; i < maxn; i++) {
if(vis[i])
ans += vis[i] * (vis[i]-1) / 2;
}
printf("%d\n", ans);
}
return 0;
}
//_CRT_SECURE_NO_WARNINGS
I.Routing Table
J.Single Round Math
大数,直接上java
import java.util.*;
import java.math.*;
public class Main{
public static void main(String[] args){
Scanner cin = new Scanner(System.in);
int T = cin.nextInt();
for(int i=1;i<=T;i++){
BigInteger n = cin.nextBigInteger();
BigInteger m = cin.nextBigInteger();
if(n.equals(m)){
if(n.mod(BigInteger.valueOf(11)).equals(BigInteger.valueOf(0))) System.out.println("YES");
else System.out.println("NO");
}else System.out.println("NO");
}
}
}
K.Last Hit
L.Circle of Friends
Tarjian缩点+SPFA最短路
#include
#include
#include
#include
#include
#include
#include
using namespace std;
const int maxn = 1e5+10;
#define LL long long
#define INF 0x3f3f3f3f
int n,m;
int sz;
int head[maxn];
int vis[maxn];
int dis[maxn];
int dfn[maxn], low[maxn], dfs_num;
int fa[maxn];
stack<int>st;
void init(){
dfs_num = 0;
memset(dfn, 0, sizeof dfn);
}
struct ndoe{
int u,v;
int nx;int w;
}e[maxn];
void add(int u,int v,int w){
++sz;
int tmp=head[u];
e[sz].nx=tmp;
head[u]=sz;
e[sz].v=v;
e[sz].w=1;
}
void tarjan(int now){
dfn[now] = low[now] = ++dfs_num;
st.push(now); vis[now] = 1;
for(int i=head[now];~i;i=e[i].nx){
int nt = e[i].v;
if(dfn[nt]&&!vis[nt]) continue;
if(!dfn[nt]){
tarjan(nt);
if(low[nt]else if(vis[nt]){
if(dfn[nt]if(dfn[now]==low[now]){
while(!st.empty()){
int tem = st.top(); st.pop();
vis[tem] = 0; fa[tem] = now;
if(tem==now) break;
}
}
}
void spfa()
{
queue<int> q;int tmp=0;dis[tmp]=0;
q.push(tmp);vis[0]=1;
while(!q.empty()){
tmp=q.front();
q.pop();
vis[tmp]=0;
for(int i=head[tmp];~i;i=e[i].nx)
{
if(fa[e[i].v]==fa[tmp]) e[i].w = 0;
if(dis[tmp]+e[i].wif(!vis[e[i].v]) q.push(e[i].v),vis[e[i].v]=1;
}
}
}
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
init();
sz=0;
memset(head,-1,sizeof head);
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++){
int u,v;
scanf("%d%d",&u,&v);
add(u,v,1);
}
memset(vis,0,sizeof vis);
memset(dis,INF,sizeof dis);
tarjan(0);
spfa();
if(dis[n-1]printf("%d\n",dis[n-1]);
}
else printf("-1\n");
}
return 0;
}