XDOJ1256-1118-1116

来源:互联网 发布:纯种狗是退化知乎 编辑:程序博客网 时间:2024/06/06 17:25
Description
BoomUUZ发飙了。ACM的培训本应该来很多人,今天却只来了那么一点点。已知每个学生能来上课的概率为Pi(1<=i<=n),当上课人数少于k时,UUZ会发飙,一旦UUZ发飙,那么以后的课(包括这节课)就都不上了,而如果不发飙,则UUZ还会开下一节课。那么,UUZ能为大家开课的期望大约是多少堂呢?精确到0.1就可以了。
Input
第一行读入case (cas<=10),表示数据组数
接下来读入case组数据,每组第一行为2个整数n(1<=n<=20),k(1<=k<=n)。
接下来一行共n个一位小数(大于0小于1),表示这n个学生来上课的概率
Output
每组数据输出一个数字(精确到0.1),表示UUZ上课的期望
Sample Input
1
3 1
0.1 0.1 0.1
Sample Output
0.4
#include<stdio.h>#include<string.h>#include<algorithm>#include<iostream>using namespace std;double dp[25][25];double ans=0;int a,b,c,d,e,f,t;double p[25];int n,k;int main(){    cin>>t;    while (t--)    {          ans=0;          memset(dp,0,sizeof(dp));          cin>>n>>k;          for (a=1;a<=n;a++) cin>>p[a];          dp[0][0]=1;          for (a=0;a<n;a++)              for (b=0;b<=a;b++)              if (dp[a][b]!=0)              {                  dp[a+1][b]+=dp[a][b]*(1-p[a+1]);                  dp[a+1][b+1]+=dp[a][b]*p[a+1];              }          double temp=0;          for (a=0;a<k;a++) temp+=dp[n][a];          temp=1-temp;          ans=temp/(1-temp);          printf("%.1lf\n",ans);    }    return 0;}

1118 - XDUgirls
Description

 There are many pretty girls in Xidian University, and as we know, every girl loves pretty clothes, so do they. One day some of them got a huge rectangular cloth and they want to cut it into small rectangular pieces to make scarves. But different girls like different style, and they voted each style a price wrote down on a list. They have a machine which can cut one cloth into exactly two smaller rectangular pieces horizontally or vertically, and ask you to use this machine to cut the original huge cloth into pieces appeared in the list. Girls wish to get the highest profit from the small pieces after cutting, so you need to find out a best cutting strategy. You are free to make as many scarves of a given style as you wish, or none if desired. Of course, the girls do not require you to use all the cloth.

Input
The first line of input consists of an integer T, indicating the number of test cases.
The first line of each case consists of three integers N, X, Y, N indicating there are N kinds of rectangular that you can cut in and made to scarves; X, Y indicating the dimension of the original cloth. The next N lines, each line consists of two integers, xi, yi, ci, indicating the dimension and the price of the ith rectangular piece cloth you can cut in.
Output
Output the maximum sum of prices that you can get on a single line for each case.

Constrains
0 < T <= 20
0 <= N <= 10; 0 < X, Y <= 1000
0 < xi <= X; 0 < yi <= Y; 0 <= ci <= 1000
Sample Input
1
2 4 4
2 2 2
3 3 9
Sample Output
9
#include<iostream>#include<string.h>using namespace std;int a,b,c,d,e,f;int t,n,x,y,arr[1050][1050];int xi[15],yi[15],ci[15];int main(){    cin>>t;    while (t--)    {          int best=0;          memset(arr,0,sizeof(arr));          cin>>n>>x>>y;          for (a=1;a<=n;a++) cin>>xi[a]>>yi[a]>>ci[a];          for (a=0;a<=x;a++)              for (b=0;b<=y;b++)                  for (int i=1;i<=n;i++)                  {                  if (xi[i]<=a && yi[i]<=b)                  {                    arr[a][b]=max(arr[a][b],arr[a][b-yi[i]]+arr[a-xi[i]][yi[i]]+ci[i]);                                        arr[a][b]=max(arr[a][b],arr[a-xi[i]][b]+arr[xi[i]][b-yi[i]]+ci[i]);                  }                  if (yi[i]<=a && xi[i]<=b)                  {                                        arr[a][b]=max(arr[a][b],arr[a][b-xi[i]]+arr[a-yi[i]][xi[i]]+ci[i]);                    arr[a][b]=max(arr[a][b],arr[a-yi[i]][b]+arr[yi[i]][b-xi[i]]+ci[i]);                  }              }          cout<<arr[x][y]<<endl;    }    return 0;} 

Problem 1116 - Slash
 
Description

 The American English slash (/) is a punctuation mark. In the early modern period, in the Fraktur script, which was widespread through Europe in the Middle Ages, one slash(/) represented a comma, while two slashes (//) represented a dash.
With the wide use of computers, slash appeared far more than at any previous time in history. On Unix-like systems and in URLs, the slash is to separate directory and file components of a path:
/home/whuacm/chaeyeon/Sherlockpp.jpg
http://acm.whu.edu.cn/
But in Windows systems, it uses (\) to separate directory and file components of a path:
C:\Users\v-yungao\Music\Shake
That really confuses me. Could you help me to judge if the string I wrote is right. 
Please notice that I would only make a mistake by changing (\) to (/) or (/) to (\). All the strings were constituted by a-z, A-Z, 0-9, (.) , (\) and (/), no other characters would appear in the strings.
A string of URL always begins with “[a-zA-Z]+://” (Notice (/) maybe changed to (\) ), in which “[a-zA-Z]+” represents any non-empty string of letters.
Windows path begins with “[a-zA-Z]:\” (Notice (\) maybe changed to (/)), in which “[a-zA-Z]” means an English letter. (e.g. “C:\\windows” is a URL not a Windows path)
The path of Unix-like system begins with (/) or (\).
I’ll give you some strings, can you tell me which type those strings belong to and those correct forms.

Input
The first line consists of an integer T, indicating the number of strings.
The next T lines, each line consists of a single non-empty string. All of those are really data from our daily life.
Output
For each string:
If it belongs to a path in Unix-like systems, output “It’s a path in Unix-like systems!” in a new line and the correct string in the next line.
If it belongs to a path in Windows system, output “It’s a path in Windows system!” in a new line and the correct string in the next line.
If it’s a URL, output “It’s a URL!” in a new line and the correct string in the next line.
The kind of each input string can be uniquely determined.

Constrains
0 < T <= 20
The length of each string will not be longer than 50.
Sample Input
4
http://acm.whu.edu.cn/felioj
http:/\acm.whu.edu.cn/11111011001/
\home\whuacm\Slash\yama
Z:\movie/chaeyeon
Sample Output
It's a URL!
http://acm.whu.edu.cn/felioj
It's a URL!
http://acm.whu.edu.cn/11111011001/
It's a path in Unix-like systems!
/home/whuacm/Slash/yama
It's a path in Windows system!
Z:\movie\chaeyeon
#include<iostream>#include<string.h>using namespace std;int a,b,c,d,e,f;int t;string s;char fuck;int main(){    fuck='\\';    cin>>t;    while (t--)    {          cin>>s;          if (s[0]=='/' || s[0]==fuck)          {            for (a=0;a<s.size();a++) if (s[a]==fuck) s[a]='/';            cout<<"It's a path in Unix-like systems!"<<endl;            cout<<s<<endl;            continue;          }          int temp=0;          while (s[temp]!=':') temp++;          if (s[temp+2]=='/' || s[temp+2]==fuck)          {            cout<<"It's a URL!"<<endl;            for (a=0;a<s.size();a++) if (s[a]==fuck) s[a]='/';            cout<<s<<endl;            continue;          }           if (s[temp+1]=='/' || s[temp+1]==fuck)          {            cout<<"It's a path in Windows system!"<<endl;            for (a=0;a<s.size();a++) if (s[a]=='/') s[a]=fuck;            cout<<s<<endl;            continue;          }    }}


0 0
原创粉丝点击