1. 程式人生 > 實用技巧 >woj1013 Barcelet 字串 woj1014 Doraemon's Flashlight 幾何

woj1013 Barcelet 字串 woj1014 Doraemon's Flashlight 幾何


title: woj1013 Barcelet 字串
date: 2020-03-18 18:00:00
categories: acm
tags: [acm,字串,woj]

字串,字典序。

1 描述

Some beads are embedded in a bracelet, and each beads is carved with a lower case letter, as the follow figure shows:

If we read the letters in counter clockwise with different initial position, we may get different strings. The above example, we can read 6 strings:
acabdb
cabdba
abdbac
bdbaca
dbacab
bacabd
Sort these strings in lexical order, we obtain:
abdbac
acabdb
bacabd
bdbaca
cabdba
dbacab
What we need is the first string: abdbac.

2 輸入輸出

輸入格式
A string of lower case letters representing the letters carved on the bracelet (in counter clockwise order).
The length of the string is no more than 100.

輸出格式
Output the first string of all the possible strings after sorting them in lexical order.

3 樣例

樣例輸入
acabdb
kkisverystupid
樣例輸出
abdbac
dkkisverystupi

4 分析

//題意,輸入字串,看成環,從任一點開始一週構成“子串”,輸出字典序最小的串
//比如 輸入 1236 子串有1236 2361 3612 6123輸出1236

因為資料量很小,就算出來所有的排列,然後sort就行

5 code

#include<iostream>
#include<algorithm>
#include<cstring> 
#include<vector>
using namespace std;

bool cmp1(string a,string b){
    return a<b;
}
bool cmp(char*a,char*b){
    return strcmp(a,b);
}

char origin[105];
char mapp[105][105];

string ori;
vector<string>ans;
string tmp;
int main(){

while(cin>>ori){
    int len=ori.length();  //string.length() .size()
        for(int i=0;i<len;i++){
            tmp=ori;
            for(int j=0;j<len;j++){
                tmp[j]=ori[(i+j)%len];
            }
            //mapp[i][len]='\0';  //essential C可以這樣,C++不行。 Array must be initialized with a brace enclosed initializer
            //mapp[i][len]=;
            ans.push_back(tmp);
        }
        sort(ans.begin(),ans.end(),cmp1);
        cout<<ans[0]<<endl;
        ans.clear();  //別忘了
}

/* 
    while(scanf("%s",origin)!=EOF){
        int len=strlen(origin);  //string.length() .size()
        for(int i=0;i<len;i++){
            for(int j=0;j<len;j++){
                mapp[i][j]=origin[(i+j)%len];
            }
            //mapp[i][len]='\0';  //essential C可以這樣,C++不行。 Array must be initialized with a brace enclosed initializer
            //mapp[i][len]=;  沒找到解決辦法 T_T 應該是初始化的問題
        }
        sort(mapp,mapp+len,cmp);
        cout<<mapp[0]<<endl;

    }
    */
    return 0;
}

title: woj1014 Doraemon's Flashlight 幾何
date: 2020-03-18 19:00:00
categories: acm
tags: [acm,幾何,數學,woj]

幾何題。矩陣*幾何體,行列式即為線性變換的伸縮因子。

1 描述

Doraemon, a robot cat from the 21st century, has a lot of magic tools. And he is always helping others. Little Ken, a little kid in Wuhan University,
is frequently teased by his classmates. So, Little Ken wants to be a big Ken, a strong Ken, instead of little Ken.
One day Doraemon heard of that the cherry blossoms in Wuhan University are more beautiful than those in Japan, so Doraemon flied to China by
his aircraft. While enjoying the blossoms, he happened to hear of Little Ken?s rough life. The kindhearted Doraemon decided to help Little Ken, you
know,to be a big Ken.

Doraemon picks out a flashlight from his pocket. The flashlight is one of his magic tools. All the objects illuminated by this flashlight will
become much bigger than before. So Doraemon points the flashlight to Little Ken. At the moment that Doraemon wants to push the button, Little
Ken cries, ?Wait a second!? Because he doubts this magic tool, Little Ken wants to test it first. He picks up a cubic and illuminates it.
The cubic changes its shape, as the following figure shows:

2 輸入輸出

輸入格式
There are several test cases. In each test case a 3*3 matrix is given, representing the transform of the flashlight. All the numbers of the matrix are integers ranging from -100 to 100, inclusively.

輸出格式
Output the volume of the object transformed from a unit cubic, round to 2 digits after the decimal point.

3 樣例

樣例輸入
1 0 1
0 2 0
-1 0 1

1 0 0
0 1 0
0 0 1

樣例輸出
4.00
1.00

4 分析

// 線性代數,行列式。。需要複習了
//二階三階行列式求值可以用沙路法(對角線法則)
//題意:給出的三階行列式是變形公式,乘unit cubic
//The coordinates of the eight vertices of the unit cubic are: (0, 0, 0),(0, 1, 0),(1, 1, 0),(1, 0, 0),(0, 0, 1),(0, 1, 1),
//(1, 1, 1),(1, 0, 1).
//Output the volume of the object transformed from a unit cubic, round to 2 digits after the decimal point.
//小數點後2位。
//然後算體積
//https://www.zhihu.com/question/36966326 這題我沒明白,看了資料說是行列式就是線性變換的伸縮因子,
//原來的體積是1,經過矩陣的線性變換的體積就是1*矩陣行列式
//可以設幾個例子看確實是這樣的
//北大數學系的hzg說是在xyz三個維度拉長,比如行列式值為4,就是拉長4^(1/3),乘起來就是4

//港大數學系的同學說就是積分換元(體積積分)

5 code

#include<cstdio>
#include<cmath>
using namespace std;

double x1;
double x2,x3;
double y11;
double y2,y3,z1,z2,z3;

int main()
{
    while(scanf("%lf%lf%lf",&x1,&x2,&x3)==3)
    {
      scanf("%lf%lf%lf",&y11,&y2,&y3); 
      scanf("%lf%lf%lf",&z1,&z2,&z3);
      printf("%.2lf\n",fabs(x1*(y2*z3-y3*z2)-y11*(x2*z3-x3*z2)+z1*(x2*y3-x3*y2)));//沙路法,對角線法則
    }
   return 0;  
}