首页 > 其他 > 详细

Codeforces Round #230

时间:2014-02-19 17:48:16      阅读:361      评论:0      收藏:0      [点我收藏+]

A. Nineteen

Alice likes word "nineteen" very much. She has a string s and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.

For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) two such words. More formally, word "nineteen" occurs in the string the number of times you can read it starting from some letter of the string. Of course, you shouldn‘t skip letters.

Help her to find the maximum number of "nineteen"s that she can get in her string.

Input

The first line contains a non-empty string s, consisting only of lowercase English letters. The length of string s doesn‘t exceed 100.

Output

Print a single integer — the maximum number of "nineteen"s that she can get in her string.

Sample test(s)
input
nniinneetteeeenn
output
2
input
nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii
output
2
input
nineteenineteen
output
2
题意:
找出能组成nineteen的个数 注意最后一个n可以是下一个nineteen的开头
代码:
bubuko.com,布布扣
 1 #include<iostream>
 2 #include<string.h>
 3 #include<stdio.h>
 4 #include<set>
 5 #include<algorithm>
 6 using namespace std;
 7 
 8 char a[105];
 9 
10 int main()
11 {
12     int n,m,e,t;
13     //freopen("aa.txt","r",stdin);
14     while(cin>>a)
15     {
16         n=m=e=t=0;
17         for(int i=0;i<strlen(a);i++)
18         {
19             if(a[i]==n)
20                 n++;
21             else if(a[i]==i)
22                 m++;
23             else if(a[i]==e)
24                 e++;
25             else if(a[i]==t)
26                 t++;
27         }
28         n=(n-1)/2;
29         e/=3;
30         int minn=n;
31         if(minn>m)
32             minn=m;
33         if(minn>e)
34             minn=e;
35         if(minn>t)
36             minn=t;
37         cout<<minn<<endl;
38     }
39     return 0;
40 }
bubuko.com,布布扣

B. Three matrices

Chubby Yang is studying linear equations right now. He came up with a nice problem. In the problem you are given an n?×?nmatrix W, consisting of integers, and you should find two n?×?n matrices A and B, all the following conditions must hold:

  • Aij?=?Aji, for all i,?j (1?≤?i,?j?≤?n);
  • Bij?=??-?Bji, for all i,?j (1?≤?i,?j?≤?n);
  • Wij?=?Aij?+?Bij, for all i,?j (1?≤?i,?j?≤?n).

Can you solve the problem?

Input

The first line contains an integer n (1?≤?n?≤?170). Each of the following n lines contains n integers. The j-th integer in the i-th line is Wij (0?≤?|Wij|?<?1717).

Output

The first n lines must contain matrix A. The next n lines must contain matrix B. Print the matrices in the format equal to format of matrix W in input. It is guaranteed that the answer exists. If there are multiple answers, you are allowed to print any of them.

The answer will be considered correct if the absolute or relative error doesn‘t exceed 10?-?4.

Sample test(s)
input
2
1 4
3 2
output
1.00000000 3.50000000
3.50000000 2.00000000
0.00000000 0.50000000
-0.50000000 0.00000000
input
3
1 2 3
4 5 6
7 8 9
output
1.00000000 3.00000000 5.00000000
3.00000000 5.00000000 7.00000000
5.00000000 7.00000000 9.00000000
0.00000000 -1.00000000 -2.00000000
1.00000000 0.00000000 -1.00000000
2.00000000 1.00000000 0.00000000
题意:
  • Aij?=?Aji, for all i,?j (1?≤?i,?j?≤?n);
  • Bij?=??-?Bji, for all i,?j (1?≤?i,?j?≤?n);
  • Wij?=?Aij?+?Bij, for all i,?j (1?≤?i,?j?≤?n).
  • 这个是最关键的了

鸡兔同笼的思路,数学方法做即可;

代码:

bubuko.com,布布扣
 1 #include<iostream>
 2 #include<string.h>
 3 #include<stdio.h>
 4 #include<set>
 5 #include<algorithm>
 6 #include<iomanip>
 7 #include<cmath>
 8 using namespace std;
 9 
10 double w[172][172];
11 double a[172][172],b[172][172];
12 int vis[172][172];
13 
14 int main()
15 {
16     int n;
17     //freopen("aa.txt","r",stdin);
18     while(cin>>n)
19     {
20         for(int i=0;i<n;i++)
21         {
22             for(int j=0;j<n;j++)
23             {
24                 cin>>w[i][j];
25             }
26         }
27         memset(vis,0,sizeof(vis));
28         for(int i=0;i<n;i++)
29         {
30             for(int j=0;j<n;j++)
31             {
32                 if(!vis[i][j]){
33                 vis[i][j]=1;
34                 vis[j][i]=1;
35                 a[i][j]=(w[i][j]+w[j][i])/2;
36                 a[j][i]=a[i][j];
37                 b[i][j]=(w[i][j]-w[j][i])/2;
38                 b[j][i]=-1.0*b[i][j];
39                 if(b[j][i]==0)
40                     b[j][i]=fabs(b[j][i]);
41                 }
42             }
43         }
44         for(int i=0;i<n;i++)
45         {
46             for(int j=0;j<n;j++)
47             {
48                 cout<<setprecision(8)<<std::fixed<<a[i][j];
49                 if(j!=n-1)
50                     cout<<" ";
51             }
52             cout<<endl;
53         }
54         for(int i=0;i<n;i++)
55         {
56             for(int j=0;j<n;j++)
57             {
58                 cout<<setprecision(8)<<std::fixed<<b[i][j];
59                 if(j!=n-1)
60                     cout<<" ";
61             }
62             cout<<endl;
63         }
64     }
65     return 0;
66 }
bubuko.com,布布扣

 

 

Codeforces Round #230

原文:http://www.cnblogs.com/zhanzhao/p/3555095.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!