• Codeforces Round #230


    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的开头
    代码:
     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 }

    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).
    • 这个是最关键的了

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

    代码:

     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 }

     C. Blocked Points

    Imagine you have an infinite 2D plane with Cartesian coordinate system. Some of the integral points are blocked, and others are not. Two integral points A and B on the plane are 4-connected if and only if:

    • the Euclidean distance between A and B is one unit and neither A nor B is blocked;
    • or there is some integral point C, such that A is 4-connected with C, and C is 4-connected with B.

    Let's assume that the plane doesn't contain blocked points. Consider all the integral points of the plane whose Euclidean distance from the origin is no more than n, we'll name these points special. Chubby Yang wants to get the following property: no special point is 4-connected to some non-special point. To get the property she can pick some integral points of the plane and make them blocked. What is the minimum number of points she needs to pick?

    Input

    The first line contains an integer n (0 ≤ n ≤ 4·107).

    Output

    Print a single integer — the minimum number of points that should be blocked.

    Sample test(s)
    input
    1
    output
    4
    input
    2
    output
    8
    input
    3
    output
    16

     题意:

    二维坐标系中,半径为n的圆内点为特殊点,圆外点为非特殊点相连

    求与非特殊点相连的特殊点的个数;

    思路:

    先讲一下高斯圆内整数点的个数问题:

     http://mathworld.wolfram.com/GausssCircleProblem.html#userconsent#

    这里同样有一个数列资料,讲的是圆内整点数列,点我传送门

    我们要求的是这一个

     只计算一次坐标轴上的点,每一个象限内的点的分布满足数列0, 1, 2, 4, 5, 7, 8, 9, 11, 12, 14, 15, ...

    特判n=0,计算公式:

    代码:

     1 #include <iostream>
     2 #include <cmath>
     3 using namespace std;
     4 
     5 int main(){
     6     int n;
     7     while (cin >> n){
     8         int x = n * sqrt(double(2));
     9         if (n == 0) cout << 1 << endl;
    10         else cout << x * 4 << endl;
    11     }
    12     return 0;
    13 }
  • 相关阅读:
    python之简单爬虫
    python之正则表达式
    python之面向对象
    python之模块与包
    python之循环嵌套与算法
    linux shell实现从函数返回数组
    linux脚本实现数组值相加
    linux中使用函数输出
    linux shelll中显示的意义
    lsof命令
  • 原文地址:https://www.cnblogs.com/zhanzhao/p/3555095.html
Copyright © 2020-2023  润新知