A - Second-price Auction

Do you know second-price auction? It's very simple but famous. In a second-price auction, each potential buyer privately submits, perhaps in a sealed envelope or over a secure connection, his (or her) bid for the object to the auctioneer. After receiving all the bids, the auctioneer then awards the object to the bidder with the highest bid, and charges him (or her) the amount of the second-highest bid.

Suppose you're the auctioneer and you have received all the bids, you should decide the winner and the amount of money he (or she) should pay.

Input

There are multiple test cases. The first line of input contains an integer T(T <= 100), indicating the number of test cases. Then T test cases follow.

Each test case contains two lines: The first line of each test case contains only one integer N, indicating the number of bidders. (2 <= N <= 100) The second line of each test case contains N integers separated by a space. The i-th integer Piindicates the i-th bidder's bid. (0 < Pi <= 60000) You may assume that the highest bid is unique.

Output

For each test case, output a line containing two integers x and y separated by a space. It indicates that the x-th bidder is the winner and the amount of money he (or she) should pay is y.

Sample Input

2
3
3 2 1
2
4 9

Sample Output

1 2
2 4

水题,上代码:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<cmath> const int maxn=1e5+5;
typedef long long ll;
using namespace std;
int a[maxn];
int b[maxn];
int main()
{
int T;
while(cin>>T)
{
while(T--)
{
int n;
cin>>n;
for(int t=0;t<n;t++)
{
scanf("%d",&a[t]);
b[t]=a[t];
}
sort(a,a+n);
int k;
for(int t=0;t<n;t++)
{
if(b[t]==a[n-1])
{
k=t+1;
}
}
cout<<k<<" "<<a[n-2]<<endl;
}
}
return 0;
}

B - Light Bulb

Compared to wildleopard's wealthiness, his brother mildleopard is rather poor. His house is narrow and he has only one light bulb in his house. Every night, he is wandering in his incommodious house, thinking of how to earn more money. One day, he found that the length of his shadow was changing from time to time while walking between the light bulb and the wall of his house. A sudden thought ran through his mind and he wanted to know the maximum length of his shadow.

Input

The first line of the input contains an integer T (T <= 100), indicating the number of cases.

Each test case contains three real numbers Hh and D in one line. H is the height of the light bulb while h is the height of mildleopard. D is distance between the light bulb and the wall. All numbers are in range from 10-2 to 103, both inclusive, and H - h >= 10-2.

Output

For each test case, output the maximum length of mildleopard's shadow in one line, accurate up to three decimal places..

Sample Input

3
2 1 0.5
2 0.5 3
4 3 4

Sample Output

1.000
0.750
4.000

三分  附队友代码

#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
double H,h,D;
double fun(double x)
{
return 1.0*h/(1.0*x*(H-h)/(D*h-H*x)+1)+1.0*x;
}
double sanfen(double l,double r)
{
if(r-l<0.00001)
return fun(l);
double mid=(l+l+r)/3;
double midd=(l+r+r)/3;
double a=fun(mid);
double b=fun(midd);
if(a>b)
return sanfen(l,midd);
else
return sanfen(mid,r);
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%lf%lf%lf",&H,&h,&D);
double tt=1.0*D*h/H;
printf("%.3f\n",sanfen(0,tt));
}
}

C - Connect them

You have n computers numbered from 1 to n and you want to connect them to make a small local area network (LAN). All connections are two-way (that is connecting computers i and j is the same as connecting computers j and i). The cost of connecting computer i and computer j is cij. You cannot connect some pairs of computers due to some particular reasons. You want to connect them so that every computer connects to any other one directly or indirectly and you also want to pay as little as possible.

Given n and each cij , find the cheapest way to connect computers.

Input

There are multiple test cases. The first line of input contains an integer T (T <= 100), indicating the number of test cases. Then T test cases follow.

The first line of each test case contains an integer n (1 < n <= 100). Then n lines follow, each of which contains n integers separated by a space. The j-th integer of the i-th line in these n lines is cij, indicating the cost of connecting computers iand j (cij = 0 means that you cannot connect them). 0 <= cij <= 60000, cij = cjicii= 0, 1 <= ij <= n.

Output

For each test case, if you can connect the computers together, output the method in in the following fomat:

ijij1 ......

where ik ik (k >= 1) are the identification numbers of the two computers to be connected. All the integers must be separated by a space and there must be no extra space at the end of the line. If there are multiple solutions, output the lexicographically smallest one (see hints for the definition of "lexicography small") If you cannot connect them, just output "-1" in the line.

Sample Input

2
3
0 2 3
2 0 5
3 5 0
2
0 0
0 0

Sample Output

1 2 1 3
-1

Hint

s:

A solution A is a line of p integers: a1a2, ...ap.

Another solution B different from A is a line of q integers: b1b2, ...bq.
A is lexicographically smaller than B if and only if:

(1) there exists a positive integer r (r <= pr <= q) such that ai = bi for all 0 < i < r and ar < br 
OR

(2) p < q and ai = bi for all 0 < i <= p

最小生成树

代码:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<cmath> const int maxn=1e2+10;
typedef long long ll; using namespace std;
int pre[maxn];
struct node
{
int x,y;
int sum;
}p[1000005];
struct node1
{
int x,y;
}mp[1000005]; int find(int x)
{
if(pre[x]==x)
{
return x;
}
else
{
return pre[x]=find(pre[x]);
}
}
bool merge(int x,int y)
{
int fx=find(x);
int fy=find(y);
if(fx!=fy)
{
pre[fx]=fy;
return true;
}
else
{
return false;
}
}
bool cmp(node x1,node y1)
{
if(x1.sum!=y1.sum)
return x1.sum<y1.sum;
else
{
if(x1.x!=y1.x)
{
return x1.x<y1.x;
}
else
{
return x1.y<y1.y;
}
}
}
bool cmp1( node1 a, node1 b){
if(a.x == b.x){
return a.y < b.y;
}
else
return a.x < b.x;
} int main()
{
int T; cin>>T;
while(T--)
{
int n;
cin>>n;
for(int t=1;t<=n;t++)
{
pre[t]=t;
}
int cnt=0;
for(int t=1;t<=n;t++)
{
for(int j=1;j<=n;j++)
{
int x;
scanf("%d",&x);
if(x!=0&&t<j)
{
p[cnt].x=t;
p[cnt].y=j;
p[cnt++].sum=x;
} }
}
sort(p,p+cnt,cmp);
int cc=0;
for(int t=0;t<cnt;t++)
{
if(cc==n-1)
{
break;
}
if(merge(p[t].x,p[t].y))
{
mp[cc].x=p[t].x;
mp[cc].y=p[t].y;
cc++; }
}
if(cc!=n-1)
{
cout<<"-1"<<endl;
continue;
}
sort(mp,mp+cc,cmp1);
for(int t=0;t<cc;t++)
{
if(t==0)
cout<<mp[t].x<<" "<<mp[t].y;
else
{
cout<<" "<<mp[t].x<<" "<<mp[t].y;
}
}
cout<<endl; } return 0;
}

F - 80ers' Memory

I guess most of us are so called 80ers, which means that we were born in the 1980's. This group of people shared a lot of common memories. For example, the Saint Seiya, the YoYo ball, the Super Mario, and so on. Do you still remember these?

Input

There will be ONLY ONE test case.

The test case begins with a positive integer N, (N < 100).

Then there will be N lines each containing a single word describing a keyword of the typical 80ers' memories. Each word consists of letters, [a-zA-Z], numbers, [0-9], and the underline, '_'. The length of each word would be no more than 20.

Then one line follows with a positive integer K, (K < 100).

The last part of the test case will be K lines. The i-th line contains the keywords given by the i-th person and starts with a positive integer Ni. Then there will be Ni words separated by white spaces. Each of these words has no more than 20 characters.

All the words are case sensitive.

Output

For each of these K people, you are asked to count the number of typical 80ers' keywords on his/her list and output it in a single line.

Sample Input

4
Saint_Seiya
YoYo_ball
Super_Mario
HuLuWa
3
2 Saint_Seiya TiaoFangZi
1 KTV
3 HuLuWa YOYO_BALL YoYo_ball

Sample Output

1
0
2

map

代码:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<cmath> const int maxn=1e5+5;
typedef long long ll;
using namespace std;
int a[maxn];
int b[maxn];
char str[1005][1005];
map<string,int>mp;
int main()
{
int n;
cin>>n;
getchar();
for(int t=1;t<=n;t++)
{
scanf("%s",&str[t]);
mp[str[t]]=t;
}
int k;
cin>>k;
for(int t=0;t<k;t++)
{
int m;
cin>>m;
int s=0;
getchar();
char str2[105];
for(int j=0;j<m;j++)
{
cin>>str2;
if(mp[str2]!=0)
{
s++;
}
}
cout<<s<<endl;
} return 0;
}

I - A Stack or A Queue?

Do you know stack and queue? They're both important data structures. A stack is a "first in last out" (FILO) data structure and a queue is a "first in first out" (FIFO) one.

Here comes the problem: given the order of some integers (it is assumed that the stack and queue are both for integers) going into the structure and coming out of it, please guess what kind of data structure it could be - stack or queue?

Notice that here we assume that none of the integers are popped out before all the integers are pushed into the structure.

Input

There are multiple test cases. The first line of input contains an integer T (T <= 100), indicating the number of test cases. Then T test cases follow.

Each test case contains 3 lines: The first line of each test case contains only one integer N indicating the number of integers (1 <= N <= 100). The second line of each test case contains N integers separated by a space, which are given in the order of going into the structure (that is, the first one is the earliest going in). The third line of each test case also contains N integers separated by a space, whick are given in the order of coming out of the structure (the first one is the earliest coming out).

Output

For each test case, output your guess in a single line. If the structure can only be a stack, output "stack"; or if the structure can only be a queue, output "queue"; otherwise if the structure can be either a stack or a queue, output "both", or else otherwise output "neither".

Sample Input

4
3
1 2 3
3 2 1
3
1 2 3
1 2 3
3
1 2 1
1 2 1
3
1 2 3
2 3 1

Sample Output

stack
queue
both
neither

模拟

代码:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<cmath> const int maxn=1e5+5;
typedef long long ll;
using namespace std;
int a[maxn];
int b[maxn];
int main()
{
int T;
queue<int>q;
stack<int>s;
while(cin>>T)
{
while(T--)
{ int n;
cin>>n;
for(int t=0;t<n;t++)
{
scanf("%d",&a[t]);
q.push(a[t]);
s.push(a[t]);
}
for(int t=0;t<n;t++)
{
scanf("%d",&b[t]); }
int flag1=0,flag2=0;
for(int t=0;t<n;t++)
{
if(b[t]!=q.front())
{
flag2=1;
}
if(b[t]!=s.top())
{
flag1=1;
}
q.pop();
s.pop();
}
if(flag1==1&&flag2==1)
{
cout<<"neither"<<endl;
}
else if(flag1==1&&flag2==0)
{
cout<<"queue"<<endl;
}
else if(flag1==0&&flag2==1)
{
cout<<"stack"<<endl;
}
else
{
cout<<"both"<<endl;
} }
}
return 0;
}

J - Dream City

JAVAMAN is visiting Dream City and he sees a yard of gold coin trees. There are ntrees in the yard. Let's call them tree 1, tree 2 ...and tree n. At the first day, each tree i has ai coins on it (i=1, 2, 3...n). Surprisingly, each tree i can grow bi new coins each day if it is not cut down. From the first day, JAVAMAN can choose to cut down one tree each day to get all the coins on it. Since he can stay in the Dream City for at most m days, he can cut down at most m trees in all and if he decides not to cut one day, he cannot cut any trees later. (In other words, he can only cut down trees for consecutive m or less days from the first day!)

Given nmai and bi (i=1, 2, 3...n), calculate the maximum number of gold coins JAVAMAN can get.

Input

There are multiple test cases. The first line of input contains an integer T (T <= 200) indicates the number of test cases. Then T test cases follow.

Each test case contains 3 lines: The first line of each test case contains 2 positive integers n and m (0 < m <= n <= 250) separated by a space. The second line of each test case contains n positive integers separated by a space, indicating ai. (0 < ai <= 100, i=1, 2, 3...n) The third line of each test case also contains npositive integers separated by a space, indicating bi. (0 < bi <= 100, i=1, 2, 3...n)

Output

For each test case, output the result in a single line.

Sample Input

2
2 1
10 10
1 1
2 2
8 10
2 3

Sample Output

10
21

Hint

s:

Test case 1: JAVAMAN just cut tree 1 to get 10 gold coins at the first day.

Test case 2: JAVAMAN cut tree 1 at the first day and tree 2 at the second day to get 8 + 10 + 3 = 21 gold coins in all.

dp,要让效益好的往后排,如果相同就数值大的在前面

代码:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<cmath> const int maxn=300;
typedef long long ll;
using namespace std; int dp[maxn][maxn];
struct node
{
int val,speed;
}p[1005];
bool cmp(node x,node y)
{
if(x.speed!=y.speed)
{
return x.speed<y.speed;
}
else
{
return x.val>y.val;
}
}
int main()
{
int T;
while(cin>>T)
{
while(T--)
{
int n,m;
memset(dp,0,sizeof(dp));
cin>>n>>m;
for(int t=1;t<=n;t++)
{
scanf("%d",&p[t].val);
}
for(int j=1;j<=n;j++)
{
scanf("%d",&p[j].speed);
}
sort(p+1,p+n+1,cmp);
for(int t=1;t<=n;t++)
{
for(int j=1;j<=m;j++)
{
dp[t][j]=max(dp[t-1][j],dp[t-1][j-1]+p[t].speed*(j-1)+p[t].val);
}
}
cout<<dp[n][m]<<endl;
}
}
return 0;
}

K - K-Nice

This is a super simple problem. The description is simple, the solution is simple. If you believe so, just read it on. Or if you don't, just pretend that you can't see this one.

We say an element is inside a matrix if it has four neighboring elements in the matrix (Those at the corner have two and on the edge have three). An element inside a matrix is called "nice" when its value equals the sum of its four neighbors. A matrix is called "k-nice" if and only if k of the elements inside the matrix are "nice".

Now given the size of the matrix and the value of k, you are to output any one of the "k-nice" matrix of the given size. It is guaranteed that there is always a solution to every test case.

Input

The first line of the input contains an integer T (1 <= T <= 8500) followed by Ttest cases. Each case contains three integers nmk (2 <= nm <= 15, 0 <= k <= (n- 2) * (m - 2)) indicating the matrix size n * m and it the "nice"-degree k.

Output

For each test case, output a matrix with n lines each containing m elements separated by a space (no extra space at the end of the line). The absolute value of the elements in the matrix should not be greater than 10000.

Sample Input

2
4 5 3
5 5 3

Sample Output

2 1 3 1 1
4 8 2 6 1
1 1 9 2 9
2 2 4 4 3
0 1 2 3 0
0 4 5 6 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0

思维,初始化全是0,其余都填数,每天一个减少一个符合的

代码:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<cmath> const int maxn=30;
typedef long long ll; int Map[maxn][maxn];
using namespace std; int main()
{ int T;
while(cin>>T)
{
while(T--)
{
memset(Map,0,sizeof(Map));
int n,m,k;
cin>>n>>m>>k;
int s=(n-2)*(m-2);
int cnt=2;
int flag=0;
for(int t=0;t<n&&flag==0;t++)
{
for(int j=0;j<m;j++)
{
if(t==n-1||j==0||j==m-1)
{
continue;
}
if(s==k)
{
flag=1;
break;
}
Map[t][j]=cnt++;
s--; }
}
for(int t=0;t<n;t++)
{
for(int j=0;j<m;j++)
{
if(j==0)
{
printf("%d",Map[t][j]);
}
else
{
printf(" %d",Map[t][j]);
}
}
printf("\n");
}
}
}
return 0;
}

qdu_组队训练(ABCFIJK)的更多相关文章

  1. QDU_组队训练(ABEFGHKL)

    A - Accurately Say "CocaCola"! In a party held by CocaCola company, several students stand ...

  2. QDU_组队训练(AJFC)

    A - Pretty Matrix DreamGrid's birthday is coming. As his best friend, BaoBao is going to prepare a g ...

  3. 组队训练3回放 ——hnqw1214

    组队训练3回放 练习赛过程回放: 开场先看最后一题, 发现是专题训练时做过的网络流原题, cst照着之前的打一遍,第一遍WA, 发现数组开小了,改大后AC. 这时候qw看B题, 一开始想不到方法, c ...

  4. 组队训练1 回放(转载至cxhscst2's blog)

      第一场组队训练……意料之中的爆炸. 开场先看题,H是斐波那契水题,qw把H切了. 同时czy看I题(排列),cst继续读其他题. czy尝试交I,PE. cst发现K是水题. cst上来敲K,WA ...

  5. 组队训练2 回放(转载至cxhscst2's blog)

    2017/3/4  12:00-17:00 Solve 9 / 13 Penalty 717 练习赛过程回放: 开场5分中J题签到(cst) 12分钟时qw签到A 这时qw继续开写M,WA,检查代码. ...

  6. 【组队训练】2016 ACM/ICPC Asia Regional Dalian Online

    因为不是一队……毫无晋级的压力……反正有压力也进不去呵呵呵…… 开场zr看1006我看1010.. 1010我一直在wa... zr的1006倒是比较轻松的过了...然后我让他帮我看10.... 跟他 ...

  7. 【组队训练】2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest

    好多oj都崩掉了,于是打了cf.. 开始开的最后一题...尼玛题好长终于看完了...神题不会.... I过了好多人..看了下,一眼题...随便敲了下,1A ]; int main(){ int n, ...

  8. 问题 J: Palindromic Password ( 2018组队训练赛第十五场) (简单模拟)

    问题 J: Palindromic Password 时间限制: 3 Sec  内存限制: 128 MB提交: 217  解决: 62[提交][状态][讨论版][命题人:admin] 题目描述 The ...

  9. 问题 C: Frosh Week(2018组队训练赛第十五场)(签到)

    问题 C: Frosh Week 时间限制: 4 Sec  内存限制: 128 MB提交: 145  解决: 63[提交][状态][讨论版][命题人:admin] 题目描述 Professor Zac ...

随机推荐

  1. 459. Repeated Substring Pattern 判断数组是否由重复单元构成

    [抄题]: Given a non-empty string check if it can be constructed by taking a substring of it and append ...

  2. 解决0RA-04031故障

    1.客户反应报表数据很慢,简单查询5分钟都出不来. 2.登陆数据库服务器检查日志:Thu Mar 21 16:20:30 2013Errors in file /opt/oracle/diag/rdb ...

  3. 关于recv的返回值

    通常recv有几种返回值 1.==0 表示收到FIN包, 因为FIN包,是状态为标记为FIN的空包,没有携带数据,所以recv的长度为0 2.>0 表示收到了数据, 但是有没有收完,是不知道的 ...

  4. js数值和字符串比较的规则

    1.数值和字符串比较时 a.若字符串为数字字符串,则将字符串转为数字,再比较 b.若字符串不为数字字符串,则直接返回false,因为这里把字符串转为了NaN, 数字与NaN比较,都返回false

  5. javascript DES加密

    研究联通wifi登陆中,发现了一个名为"encryption.js"的文件.这个文件一看即知是加密过的,首先自己尝试去手工解密,看到太烦琐了,忽然想到网上有js解密工具,遂决定用来 ...

  6. ArcGIS坐标转换

    我忘了怎么设置坐标系了- 定义投影ArcCatalog设置?  -arctoolbox好像都可以   感觉不用想的那么复杂]直接定义投影就行了  选这一个吗  这个就行了'  然后?  应该是先定义成 ...

  7. 编写高质量代码改善C#程序的157个建议——建议46:显式释放资源需继承接口IDisposable

    建议46:显式释放资源需继承接口IDisposable C#中的每一个类型都代表一种资源,资源分为两类: 托管资源:由CLR管理分配和释放的资源,即从CLR里new出来的对象. 非托管资源:不受CLR ...

  8. POJ - 2586 Y2K Accounting Bug (找规律)

    Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vital data for ...

  9. Android Service基本知识总结(一)

    一.简介 Service是Android系统的后台服务组件,适用于开发无界面.长时间运行的应用功能Service特点如下: 没有用户界面 不会轻易被Android系统终止 在系统资源恢复后Servic ...

  10. 策略(Strategy)模式

    /* * 环境(Context)角色:持有一个Strategy类的引用. * 抽象策略(Strategy)角色:这是一个抽象角色,通常由一个接口或抽象类实现.此角色给出所有的具体策略类所需的接口. * ...