20140323组队赛 2012福建省第三届ACM省赛题目
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
System Crawler (2014-03-17)
Description
You are given two positive integers A and B in Base C. For the equation:
A=k*B+d
We know there always existing many non-negative pairs (k, d) that satisfy the equation above. Now in this problem, we want to maximize k.
For example, A="123" and B="100", C=10. So both A and B are in Base 10. Then we have:
(1) A=0*B+123
(2) A=1*B+23
As we want to maximize k, we finally get one solution: (1, 23)
The range of C is between 2 and 16, and we use 'a', 'b', 'c', 'd', 'e', 'f' to represent 10, 11, 12, 13, 14, 15, respectively.
Input
The first line of the input contains an integer T (T≤10), indicating the number of test cases.
Then T cases, for any case, only 3 positive integers A, B and C (2≤C≤16) in a single line. You can assume that in Base 10, both A and B is less than 2^31.
Output
Sample Input
3
2bc 33f 16
123 100 10
1 1 2
Sample Output
(0,700)
(1,23)
(1,0)
分析:给两个整数A、B(C进制),根据公式A=k*B+d;求k,d>=0时k最大时的一组解。如果A<B,那么答案是(0,A)。如果A>=B,那么答案是((int)A/B,A%B)。
#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
using namespace std; __int64 get_num(char *s,int c)
{
int i,n=strlen(s)-;
__int64 num=;
for(i=n;i>=;i--)
{
if(''<=s[i] && s[i]<='') num+=(int)pow(c*1.0,(n-i)*1.0)*(s[i]-'');
else num+=(int)pow(c*1.0,(n-i)*1.0)*(s[i]-'a'+);
}
return num;
} int main()
{
int T,C;
__int64 A,B;
char s1[],s2[];
scanf("%d",&T);
while(T--)
{
scanf("%s %s %d",s1,s2,&C);
A=get_num(s1,C);
B=get_num(s2,C);
if(A<B)
{
printf("(0,%I64d)\n",A);
}
else printf("(%I64d,%I64d)\n",A/B,A%B);
}
return ;
}
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
System Crawler (2014-03-02)
Description
Bin has a dream that he and Jing are both in a wonderland full of beautiful gifts. Bin wants to choose some gifts for Jing to get in her good graces.
There are N different gifts in the wonderland, with ID from 1 to N, and all kinds of these gifts have infinite duplicates. Each time, Bin shouts loudly, “I love Jing”, and then the wonderland random drop a gift in front of Bin. The dropping probability for gift i (1≤i≤N) is P(i). Of cause, P(1)+P(2)+…+P(N)=1. Bin finds that the gifts with the higher ID are better. Bin shouts k times and selects r best gifts finally.
That is, firstly Bin gets k gifts, then sorts all these gifts according to their ID, and picks up the largest r gifts at last. Now, if given the final list of the r largest gifts, can you help Bin find out the probability of the list?
Input
The first line of the input contains an integer T (T≤2,000), indicating number of test cases.
For each test cast, the first line contains 3 integers N, k and r (1≤N≤20, 1≤k≤52, 1≤r≤min(k,25)) as the description above. In the second line, there are N positive float numbers indicates the probability of each gift. There are at most 3 digits after the decimal point. The third line has r integers ranging from 1 to N indicates the finally list of the r best gifts’ ID.
Output
Sample Input
4
2 3 3
0.3 0.7
1 1 1
2 3 3
0.3 0.7
1 1 2
2 3 3
0.3 0.7
1 2 2
2 3 3
0.3 0.7
2 2 2
Sample Output
0.027000
0.189000
0.441000
0.343000
题目大意:有N种礼物,每喊一次掉下一个礼物,每个礼物掉下来的概率为pi,呼喊k次,只选取r个编号较大的礼物。
分析:根据排列组合来计算概率,设编号ai有ni个,由于k可能大于r,根据乘法原理它概率分两部分:
第一部分:r个中最小编号(minn)外的概率Power(p[i],m[i])*C(m[i],r)*Power(p[i+1],m[i+1])*C(m[i+1],r-m[i])....;
第二部分:k-r个礼物,有多种情况(最小编号的个数(0,k-r))。可以把小于最小编号的看成一个种礼物(p=sum{pi,i<minn}),根据加法原理计算。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<map>
using namespace std; int N,K,R;
double p[]; inline int min(int a,int b){ return a<b?a:b;} double Power(double a,int b)
{
double ret=;
while(b)
{
if(b&) ret=ret*a;
a=a*a;
b>>=;
}
return ret;
} __int64 C(int k,int n)
{
int i;
__int64 ans=;
for ( i = ; i <=k ; i++)
{
ans*= (n-i+);
ans/=i;
}
return ans;
} int main()
{
int T,i,temp,Min,kk,rt;
double Minp,ans,tp;
map<int,int> m;
scanf("%d",&T);
while(T--)
{
m.clear();
Min=;Minp=;ans=1.0;
scanf("%d %d %d",&N,&K,&R);
kk=K;
for(i=;i<=N;i++) scanf("%lf",p+i);
for(i=;i<=R;i++){ scanf("%d",&temp);m[temp]++;Min=min(Min,temp);}
for(i=;i<Min;i++) Minp+=p[i];
for(i=Min+;i<=N;i++)
{
if(m[i]>)
{
ans*=Power(p[i],m[i])*C(m[i],kk);
kk=kk-m[i];
}
}
tp=;
for(i=;i<=K-R; i++)
{
rt=K-R-i;
tp+=((Power(p[Min],m[Min]+i)*C(m[Min]+i,K-R+m[Min])) * Power(Minp,rt));
}
ans*=tp;
printf("%.6lf\n",ans);
}
return ;
}
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
System Crawler (2012-12-11)
Description
In this problem, we have f(n,x)=Floor[n/x]. Here Floor[x] is the biggest integer such that no larger than x. For example, Floor[1.1]=Floor[1.9]=1, Floor[2.0]=2.
You are given 3 positive integers n, L and R. Print the result of f(n,L)+f(n,L+1)+...+f(n,R), please.
Input
The first line of the input contains an integer T (T≤100), indicating the number of test cases.
Then T cases, for any case, only 3 integers n, L and R (1≤n, L, R≤10,000, L≤R).
Output
Sample Input
3
1 2 3
100 2 100
100 3 100
Sample Output
0
382
332
#include<stdio.h> int main()
{
int n,l,r,t;
int sum;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&n,&l,&r);
sum = ;
for(int i =l;i<=r;i++)
{
sum +=(int)(n/i*1.0);
}
printf("%d\n",sum);
}
return ;
}
Time Limit:10000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
System Crawler (2012-12-11)
Description
Given N integers A={A[0],A[1],...,A[N-1]}. Here we have some operations:
Operation 1: AND opn L R
Here opn, L and R are integers.
For L≤i≤R, we do A[i]=A[i] AND opn (here "AND" is bitwise operation).
Operation 2: OR opn L R
Here opn, L and R are integers.
For L≤i≤R, we do A[i]=A[i] OR opn (here "OR" is bitwise operation).
Operation 3: XOR opn L R
Here opn, L and R are integers.
For L≤i≤R, we do A[i]=A[i] XOR opn (here "XOR" is bitwise operation).
Operation 4: SUM L R
We want to know the result of A[L]+A[L+1]+...+A[R].
Now can you solve this easy problem?
Input
The first line of the input contains an integer T, indicating the number of test cases. (T≤100)
Then T cases, for any case, the first line has two integers n and m (1≤n≤1,000,000, 1≤m≤100,000), indicating the number of elements in A and the number of operations.
Then one line follows n integers A[0], A[1], ..., A[n-1] (0≤A[i]<16,0≤i<n).
Then m lines, each line must be one of the 4 operations above. (0≤opn≤15)
Output
Sample Input
1
4 4
1 2 4 7
SUM 0 2
XOR 5 0 0
OR 6 0 3
SUM 0 2
Sample Output
7
18
Hint
A = [1 2 4 7]
SUM 0 2, result=1+2+4=7;
XOR 5 0 0, A=[4 2 4 7];
OR 6 0 3, A=[6 6 6 7];
SUM 0 2, result=6+6+6=18.
//;Write by lk1993, 2014.3.23
#include <stdio.h>
#include <string.h> const int M = + ; int sum[M]; inline void pushDown(int rt)
{
if(sum[rt] >= )
{
sum[rt << ] = sum[rt << | ] = sum[rt];
sum[rt] = -;
}
} inline void pushUp(int rt)
{
if(sum[rt << ] != - && sum[rt << | ] != - && sum[rt << ] == sum[rt << | ])
{
sum[rt] = sum[rt << ];
}
} void build(int l, int r, int rt)
{
if(l == r)
{
scanf("%d", &sum[rt]);
return ;
}
int m = (l + r) >> ;
build(l, m, rt << );
build(m + , r, rt << | );
pushUp(rt);
} void update(char op, int val, int ul, int ur, int l, int r, int rt)
{
if(ul <= l && ur >= r)
{
if(sum[rt] >= )
{
if('A' == op) sum[rt] &= val;
else if('X' == op) sum[rt] ^= val;
else if('O' == op) sum[rt] |= val;
return ;
}
}
pushDown(rt);
int m = (l + r) >> ;
if(ul <= m)
{
update(op, val, ul, ur, l, m, rt << );
}
if(ur > m)
{
update(op, val, ul, ur, m + , r, rt << | );
}
pushUp(rt);
} int query(int ql, int qr, int l, int r, int rt)
{
if(ql <= l && qr >= r)
{
if(sum[rt] >= )
{
return sum[rt] * (r - l + );
}
}
pushDown(rt);
int m = (l + r) >> ;
int ret = ;
if(ql <= m)
{
ret += query(ql, qr, l, m, rt << );
}
if(qr > m)
{
ret += query(ql, qr, m + , r, rt << | );
}
return ret;
} int main(int argc, char* argv[])
{
#ifdef __MYLOCAL
freopen("in.txt", "r", stdin);
#endif int t, n, m, a, b, c;
char oper[]; scanf("%d", &t);
while(t--)
{
scanf("%d%d", &n, &m);
memset(sum, -, sizeof(sum));
build(, n, );
while(m--)
{
scanf("%s", oper);
if('S' == oper[])
{
scanf("%d%d", &a, &b);
printf("%d\n", query(a + , b + , , n, ));
}
else
{
scanf("%d%d%d", &a, &b, &c);
update(oper[], a, b + , c + , , n, );
}
}
} return ;
}
System Crawler (2012-12-11)
Description
Cao Cao was hunted down by thousands of enemy soldiers when he escaped from Hua Rong Dao. Assuming Hua Rong Dao is a narrow aisle (one N*4 rectangle), while Cao Cao can be regarded as one 2*2 grid. Cross general can be regarded as one 1*2 grid.Vertical general can be regarded as one 2*1 grid. Soldiers can be regarded as one 1*1 grid. Now Hua Rong Dao is full of people, no grid is empty.
There is only one Cao Cao. The number of Cross general, vertical general, and soldier is not fixed. How many ways can all the people stand?
Input
There is a single integer T (T≤4) in the first line of the test data indicating that there are T test cases.
Then for each case, only one integer N (1≤N≤4) in a single line indicates the length of Hua Rong Dao.
Output
Sample Input
2
1
2
Sample Output
0
18
Hint
#include<iostream>
#include<cstdio>
using namespace std; bool vis[][];
int N,ans; void dfs(int i,int j)
{
if(j>)
{
i++;j=;
if(i>N)
{
ans++;return ;
}
}
if(vis[i][j]) dfs(i,j+);
if(!vis[i][j])
{
vis[i][j]=true;dfs(i,j+);vis[i][j]=false;
}
if(!vis[i][j] && j+<= && !vis[i][j+])
{
vis[i][j]=vis[i][j+]=true;
dfs(i,j+);
vis[i][j]=vis[i][j+]=false;
}
if(!vis[i][j] && i+<=N && !vis[i+][j])
{
vis[i][j]=vis[i+][j]=true;
dfs(i,j+);
vis[i][j]=vis[i+][j]=false;
}
return ;
}
int main()
{
int T,i,j;
scanf("%d",&T);
while(T--)
{
scanf("%d",&N);
ans=;
for(i=;i<N;i++)
{
for(j=;j<;j++)
{
memset(vis,false,sizeof(vis));
vis[i][j]=vis[i][j+]=vis[i+][j]=vis[i+][j+]=true;
dfs(,);
}
}
printf("%d\n",ans);
}
return ;
}
System Crawler (2013-10-19)
Description
Input
The first line of the input contains an integer T (T≤10), indicating the number of test cases.
For each test case:
The first line contains one integer n (1≤n≤100), the number of stars.
The next n lines each contains two integers x and y (0≤|x|, |y|≤1,000,000) indicate the points, all the points are distinct.
Output
Sample Input
1
3
0 0
10 0
5 1000
Sample Output
1
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std; typedef __int64 LL ;
struct Point {
LL x, y;
Point(LL x=, LL y=):x(x),y(y) { }
}p[]; typedef Point Vector; Vector operator + (const Vector& A, const Vector& B) { return Vector(A.x+B.x, A.y+B.y); }
Vector operator - (const Point& A, const Point& B) { return Vector(A.x-B.x, A.y-B.y); }
Vector operator * (const Vector& A, double p) { return Vector(A.x*p, A.y*p); }
double Dot(const Vector& A, const Vector& B) { return A.x*B.x + A.y*B.y; }
double Cross(const Vector& A, const Vector& B) { return A.x*B.y - A.y*B.x; }
double Length(const Vector& A) { return sqrt(Dot(A, A)); } Point read_point()
{
Point a;
scanf("%I64d %I64d",&a.x,&a.y);
return a;
} bool is_ok(int i,int j,int k)
{
bool flag=;
if(-Dot(p[j]-p[i],p[k]-p[i])>0.0000001) flag=;
if(-Dot(p[j]-p[k],p[i]-p[k])>0.0000001) flag=;
if(-Dot(p[i]-p[j],p[k]-p[j])>0.0000001) flag=;
return flag;
}
int main()
{
int T,i,n,j,k,ans;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(i=;i<n;i++) p[i]=read_point();
ans=;
for(i=;i<n;i++)
{
for(j=i+;j<n;j++)
{
for(k=j+;k<n;k++)
{
if(is_ok(i,j,k))
ans++;
}
}
}
printf("%d\n",ans);
}
return ;
}
System Crawler (2013-05-11)
Description
Now you are given one non-negative integer n in 10-base notation, it will only contain digits ('0'-'9'). You are allowed to choose 2 integers i and j, such that: i!=j, 1≤i<j≤|n|, here |n| means the length of n’s 10-base notation. Then we can swap n[i] and n[j].
For example, n=9012, we choose i=1, j=3, then we swap n[1] and n[3], then we get 1092, which is smaller than the original n.
Now you are allowed to operate at most M times, so what is the smallest number you can get after the operation(s)?
Please note that in this problem, leading zero is not allowed!
Input
The first line of the input contains an integer T (T≤100), indicating the number of test cases.
Then T cases, for any case, only 2 integers n and M (0≤n<10^1000, 0≤M≤100) in a single line.
Output
Sample Input
3
9012 0
9012 1
9012 2
Sample Output
9012
1092
1029
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std; int len,findex;
char s[]; struct node
{
char ch;
int x;
}t; void find_min1()
{
t.ch='';t.x=len;
for(int j=len-;j>findex;j--)
{
if(s[j]<s[findex] && s[j]<=t.ch)
{
t.ch=s[j];
t.x=j;
}
}
} void find_min2()
{
t.ch='';t.x=len;
for(int j=len-;j>findex;j--)
{
if(s[j]<s[findex] && s[j]<=t.ch && s[j]>'')
{
t.ch=s[j];
t.x=j;
}
}
} void Swap(int i,int j)
{
char ch=s[i];
s[i]=s[j];s[j]=ch;
} int main()
{
int T,n,i;
scanf("%d",&T);
while(T--)
{
scanf("%s %d",s,&n);
len=strlen(s);
findex=;
for(i=;i<n;)
{
if(findex==len-) break;
find_min1();
if(findex== && t.ch=='') find_min2();
if(t.x==len)
{
findex++;
continue;
}
else
{
Swap(findex,t.x);
findex++;i++;
}
}
printf("%s\n",s);
}
return ;
}
20140323组队赛 2012福建省第三届ACM省赛题目的更多相关文章
- [2012山东省第三届ACM大学生程序设计竞赛]——n a^o7 !
n a^o7 ! 题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2413 Time Lim ...
- Sdut 2409 The Best Seat in ACM Contest(山东省第三届ACM省赛 H 题)(模拟)
题目描述 Cainiao is a university student who loves ACM contest very much. It is a festival for him once ...
- [2012山东省第三届ACM大学生程序设计竞赛]——Mine Number
Mine Number 题目:http://acm.sdut.edu.cn/sdutoj/problem.php? action=showproblem&problemid=2410 Time ...
- 山东省第三届ACM省赛
Solved ID PID Title Accepted Submit A 2407 Impasse (+) 0 0 B 2415 Chess 0 0 C 2414 An interest ...
- Sdut 2416 Fruit Ninja II(山东省第三届ACM省赛 J 题)(解析几何)
Time Limit: 5000MS Memory limit: 65536K 题目描述 Haveyou ever played a popular game named "Fruit Ni ...
- sdut2408 pick apples (贪心+背包)山东省第三届ACM省赛
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/svitter/article/details/24642587 本文出自:http://blog.c ...
- 2012-2014 三年浙江 acm 省赛 题目 分类
The 9th Zhejiang Provincial Collegiate Programming Contest A Taxi Fare 25.57% (166/649) (水 ...
- [原]sdut2624 Contest Print Server (大水+大坑)山东省第四届ACM省赛
本文出自:http://blog.csdn.net/svitter 原题:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&am ...
- [2012山东ACM省赛] Pick apples (贪心,完全背包,枚举)
Pick apples Time Limit: 1000MS Memory limit: 165536K 题目描述 Once ago, there is a mystery yard which on ...
随机推荐
- 解决cocos simpleAudioEngine播放mp3失败问题
今天用cocos3.x版本实现游戏音乐播放发现一个坑,策划发来的mp3格式音频,用 simpleAudioEngine无法播放, 以为是路径问题,断点调试没找到,然后拷贝了cocos自带的mp3音频文 ...
- ES6学习总结 (二)
一:ES6为函数做了哪些扩展 参数的默认值 传统写法: function person(n,a){ var name =n || "zhangsan"; var age = a | ...
- Typescript学习(一)----准备篇(vscode编译ts文件)
什么是typescript? typescript是微软开发的一个脚本语言.他是JavaScript的超级,他遵循es6语法规范,他扩展了JavaScript的语法. 理解es5,es6,javasc ...
- Java常用的一些容器
转自:https://www.cnblogs.com/LipeiNet/p/5888513.html 前言:在java开发中我们肯定会大量的使用集合,在这里我将总结常见的集合类,每个集合类的优点和缺点 ...
- OpenCV中的图像形态学转换
两个基本的形态学操作是腐蚀和膨胀.他们的变化构成了开运算,闭运算,梯度等.下面以这张图为例 1.腐蚀 这个操作会把前景物体的边界腐蚀掉. import cv2 import numpy as np i ...
- hdu-2553 N皇后问题(搜索题)
在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在与棋盘边框成45角的斜线上. 你的任务是,对于给定的N,求出有多少种合法的放置方法. Inpu ...
- Linux学习-可唤醒停机期间的工作任务
什么是 anacron anacron 并不是用来取代 crontab 的,anacron 存在的目的就在于我们上头提到的,在处理非 24 小 时一直启动的 Linux 系统的 crontab 的执行 ...
- C++实现Behavioral - Observer模式 (转)
转http://patmusing.blog.163.com/blog/static/13583496020101501923571/ 也称为Dependents或Publish-Subscribe模 ...
- private virtual in c++
source from http://blog.csdn.net/steedhorse/article/details/333664 // Test.cpp #include <iostream ...
- CSS预处理器(less 和 sass)
CSS预处理器 1.基于CSS的另一种语言 2.通过工具编译成CSS 3.添加了很多CSS不具备的特性 4.能提升CSS文件的组织 提供功能:1.嵌套 反映层级和约束 2.变量和计算,减少重复戴拿 3 ...