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 ...
随机推荐
- 《队长说得队》【Alpha】Scrum meeting 5
项目 内容 这个作业属于哪个课程 >>2016级计算机科学与工程学院软件工程(西北师范大学) 这个作业的要求在哪里 >>实验十二 团队作业8:软件测试与ALPHA冲刺 团队名称 ...
- 面向对象OONo.3单元总结
一,JML语言 1)JML理论基础:JML是一类语言,用来描述一个方法或一个类的功能.以及这个类在实现这个功能时需要的条件.可能改变的全局变量.以及由于条件问题不能实现功能时这个方法或类的行为,具有明 ...
- javaweb基础(11)_cookie的会话管理
一.会话的概念 会话可简单理解为:用户开一个浏览器,点击多个超链接,访问服务器多个web资源,然后关闭浏览器,整个过程称之为一个会话. 有状态会话:一个同学来过教室,下次再来教室,我们会知道这个同学曾 ...
- scanf()的使用
scanf函数称为格式输入函数,即按用户指定的格式从键盘上把数据输入到指定的变量之中. 如下面代码: #include<stdio.h> int main() { int a,b; sca ...
- 课下作业04-2String的使用方法
1.动手动脑之String.equals()方法public class StringEquals { public static void main(String[] args) { String ...
- iOS开发遇到的坑之六--使用cocopods管理第三方库时,编译出现Library not found for -lPods问题的解决办法
在项目中有时候会遇到Library not found for -lPods(这里的IPods指的是你具体的第三方库)的问题 出现这个错误的原因是:xcode在编译的时候找不到这个库,从而导致项目无法 ...
- nodejs写一个简单的Web服务器
目录文件如 httpFile.js如下: const httpd = require("http"); const fs = require("fs"); // ...
- STL之map操作[转]
转自https://www.cnblogs.com/yutongzhu/p/5884269.html 作者彼得朱 map 是一种有序无重复的关联容器. 关联容器与顺序容器不同,他们的元素是按照关键字来 ...
- mysql关联查询
mysql数据库的统计------生成统计信息 1.distinct:在一组之中将各个唯一的值找出来,如找出所有的品牌种类 mysql>select distinct brand_kind fr ...
- Linux下打包解压命令
tar 压缩: tar -cvjpf etc.tar.bz2 /etc //-c为创建一个打包文件,相应的-f后面接创建的文件的名称,使用了.tar.bz2后缀,-j标志使用bzip2压缩,最后面为具 ...