暑假作业 一.热身


from https://vjudge.net/contest/308049

A - The 3n + 1 problem

#include <iostream>
using namespace std;
//没说第一个数字大,但仍输出原来的第一位
int main()
{
    int n,m,i,j,cnt,max_cnt,ii,jj;
    while(cin >> i >> j){
        ii=i;
        jj=j;
        cnt=0;
        max_cnt=0;
        if(i>j){
            m=i;
            i=j;
            j=m;
        }
        for(m=i;m<=j;m++){
            cnt=1;//不会计算第一次
            n=m;//n,m必须分开,否则的数字一直会为1
            while (n!=1){
                cnt++;
                if(n%2==1) n=3*n+1;
                else n=n/2;
            }
            if(cnt>max_cnt)max_cnt=cnt;
        }
        cout << ii << " " << jj << " " <<max_cnt << endl;
    }
    return 0;
}

B - Candy Sharing Game

#include <iostream>
#include <string>
using namespace std;
int isequal(int *ls,int i)
{
    int flag=ls[0];
    for(int j=1;j<i;j++){
        if(ls[j]!=flag)
            return 0;
    }
    return 1;
}
int main()
{
    int n,j,i,cnt;
    int ls[100000];
    while(cin >> n){
        if(n==0)break;
        for(i=0;i<n;i++)
            cin >> ls[i];
        cnt=0;
        while(1){
            cnt++;
            //one turn
            int last=ls[n-1];//先记录最后一个
            for(j=i-1;j>0;j--){//应该从右往左算
                ls[j]=ls[j]/2+ls[j-1]/2;
            }
            ls[0]=ls[0]/2+last/2;
            //give one cake
            for(j=0;j<i;j++){
                if(ls[j]%2==1)
                    ls[j]++;
            }
            //is equal?
            if(isequal(ls,n))
                break;
        }
        cout << cnt << " " << ls[0] << endl;
    }
    return 0;
}

C - Edge(题目看不懂)

https://blog.csdn.net/thestarfish/article/details/46850619
题意:就是行走,然后输出走过的点,首先给出两个点(300,420)-> (310,420),然后A是顺时针,V是逆时针走,每次行走都是走10个单位,并且角度是90度,输出每个转弯点

#include <iostream>
#include <string>
using namespace std;
int main()
{
    int x=300,y=420;
    string dirs[4]={"right","down","left","up"};
    string dir=dirs[0];
    string s;
    while(cin >> s){
        cout << "300 420 moveto" << endl;
        cout << "310 420 lineto" << endl;
        int len=s.length();
        int i;
        int choice=0;
        char p;
        for(i=0;i<len;i++){
            p=s[i];
            if(p=='A')
                choice++;
            if(p=='V')
                choice+=3;
            dir=dirs[choice%4];
            if(dir=="right")
                x+=10;
            if(dir=="down")
                y-=10;
            if(dir=="left")
                x-=10;
            if(dir=="up")
                y+=10;
            cout << x << " " << y << " " << "lineto" << endl;
        }
        cout << "stroke" << endl;
        cout << "showpage" << endl;
    }
    return 0;
}

D - 不容易系列之(3)―― LELE的RPG难题 (recursive)

递推问题 越界 函数调用超时

https://blog.csdn.net/why850901938/article/details/50116937
n个方格的涂色方案可以由n - 1的涂色方案追加一个得出,分两种情况:
1.在n - 1的合法涂色方案后追加一个方格,由于合法方案的首尾颜色不同,因此第n个方格的颜色必定是这两种颜色之外的一种,即方案数为f[n - 1]。
2.在n - 1的不合法涂色方案(首尾颜色相同)后追加一个合法的涂色方格,也可能使其成为长度为n的合法涂色方案,而这种不合法涂色方案的结构必定是f[n - 2]合法方案 + 首格颜色 + 首格外的两种颜色,即方案数为2 * f[n - 2]。

//Time Limit Exceeded
#include<iostream>
using namespace std;
int f(int n)
{
    if(n==1)return 3;
    else if(n==2)return 6;
    else if(n==3)return 6;
    else return f(n-1)+2*f(n-2);
}
int main()
{
    int n;
    while(cin>>n)
        cout<<f(n)<<endl;
    return 0;
}
//Time Limit Exceeded

//Accepted
#include<iostream>
using namespace std;
//超过32 int越界
int main()
{
    long long n,ls[51],i;
    ls[1]=3;
    ls[2]=6;
    ls[3]=6;
    while(cin>>n){
        for(i=4;i<=n;i++)
            ls[i]=ls[i-1]+2*ls[i-2];
        cout<<ls[n]<<endl;
    }
    return 0;
}
//Accepted

E - A + B

#include <iostream>
#include <string>
using namespace std;
int trantonum(string a)
{
    int i;
    string ls[]={"zero","one","two","three","four","five","six","seven","eight","nine"};
    for(i=0;i<10;i++){
        if(a==ls[i])
            return i;
    }
    return 0;
}
int getnum(void)
{
    string a;
    int units=0,num=0;
    while(cin>>a){
        if(a=="="||a=="+")
            break;
        units=trantonum(a);
        num=units+num*10;
    }
    return num;
}
int main()
{
    string a;
    int num1,num2;
    while(1){
        num1=getnum();
        num2=getnum();
        if(num1==0&&num2==0)
            break;
        cout << num1+num2 << endl;
    }
    return 0;
}

F - Robot Motion

#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
char grid[12][12];//创造一个12*12的矩阵,边界位置的值定为'0'
int main()
{
    int row,column,in,r,c,i;
    while(cin >> row >> column >> in){
        int X=in,Y=1;
        memset(grid,'0',sizeof(grid));
        if(row==0)break;
        string str;
        for(r=0;r<row;r++){
            cin >> str;
            for(c=1,i=0;c<=column;c++,i++)
                grid[r+1][c]=str[i];
        }
        vector<int>road;
        vector<int>::iterator p;
        int flag=X*10+Y;//记录走过的地方
        road.push_back(flag);
        int cnt=0;
        while(1){
            cnt++;
            char dir=grid[Y][X];
            if(dir=='N')Y-=1;
            else if(dir=='E')X+=1;
            else if(dir=='S')Y+=1;
            else if(dir=='W')X-=1;
            flag=X*10+Y;
            //判断以前是否走过以前的地方
            p = std::find(road.begin(),road.end(),flag);
            if(p!=road.end()){//FOUND!
                int pre=distance(road.begin(),p);
                int last=distance(p,road.end());
                cout<<pre<<" step(s) before a loop of "<<last<<" step(s)"<<endl;
                break;
            }
            //判断是否出去了
            if(grid[Y][X]=='0'){
                cout<<cnt<<" step(s) to exit"<<endl;
                break;
            }
            road.push_back(flag);
        }
    }
    return 0;
}

G - Football Game(结构体保存数据后sort)

题目看错很多次,先审题
字符串比较不用==,用strcpy,我也不知道为啥子

#include <cstring>
#include <cstdio>
#include <algorithm>
int num=-1;
using namespace std;
typedef struct info
{
    char name[100];
    int score,win,lose,net;
}info;
int in(char names[][100],char *name)
{
    int i;
    for(i=0;i<=num;i++){
        if(strcmp(name,names[i])==0)//name==names[i] ,when the length includes '\0' shit!
            return i;
    }
    return -1;
}
bool down(info a,info b)
{
    if(a.score!=b.score)//firstly compare the score
        return a.score>b.score;
    else if(a.net!=b.net)//secondly, if the scores are the same, compare the net goals
        return a.net>b.net;
    else if(a.win!=b.win)//If two teams have the same score 
    //and the same net goal, the one whose kicked in balls is bigger will be ahead.
        return a.win>b.win;
    else{//If two teams have the same score and the same net goal and the same kicked in balls, they will be outputed in alphabetic order.
        int t=strcmp(a.name,b.name);//a.name>b.name is wrong
        if(t==-1)
            return true;
        else
            return false;
    }
}
int main()
{
    int n;
    info ls[1000];
    char names[100][100]={"a","b","c"};
    char a[100],b[100],st[100];//char *a,*b,*st;
    int as,bs;
    while(~scanf("%d",&n)){//this is lost
        num=-1;
        memset(ls,0,sizeof(ls));
        for(int cnt=0;cnt<n*(n-1);cnt++){
            scanf("%s %s %s %d:%d",a,st,b,&as,&bs);//scanf("%s %s %s %d:%d",a,st,b,&as,&bs)
            int t1=in(names,a),t2=in(names,b);
            if(t1<0){
                num++;
                strcpy(ls[num].name,a);
                strcpy(names[num],a);
                ls[num].score=0,ls[num].win=0,ls[num].lose=0,ls[num].net=0;
            }
            if(t2<0){
                num++;
                strcpy(ls[num].name,b);
                strcpy(names[num],b);
                ls[num].score=0,ls[num].win=0,ls[num].lose=0,ls[num].net=0;
            }
            //add to ls
            t1=in(names,a),t2=in(names,b);
            if(as>bs)
                ls[t1].score+=3;
            else if(as<bs)
                ls[t2].score+=3;
            else if(as==bs){
                ls[t1].score+=1;
                ls[t2].score+=1;
            }
            ls[t1].win+=as;
            ls[t1].lose+=bs;
            ls[t2].win+=bs;
            ls[t2].lose+=as;
            ls[t1].net+=as-bs;
            ls[t2].net+=bs-as;
        }
    sort(ls,ls+n,down);
    for(int i=0;i<n;i++)
        printf("%s %d\n",ls[i].name,ls[i].score);
    printf("\n");
    }
    return 0;
}

H-请用sort

还是要用结构体排序,一个为满意值,一个为索引。最后把得出的索引放到新数组降序输出

#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
int n,m,k;
int data[100],indice[100];
struct s
{
    double x;
    int indice;
}a[300];
bool down(int a,int b)
{
    return a>b;
}
bool cmp(struct s a,struct s b)
{
    if(a.x!=b.x)
        return a.x>b.x;
    else
        return a.indice<b.indice;
}
int main()
{
    while(cin>>n>>m>>k){
        memset(a,0,sizeof(a));
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                double t;
                cin >> t;
                a[j].indice=j;
                a[j].x+=t;
            }
        }
        sort(a+1,a+m+1,cmp);
        int ans[300];
        for(int i=1;i<=k;i++)
            ans[i]=a[i].indice;
        sort(ans+1,ans+k+1,down);
        for(int i=1;i<=k;i++){
            cout << ans[i];
            if(i!=k)
                cout<<" ";
        }
        cout<<endl;
    }
}

I - 辗转相除法求最小公倍数 (__int64)

https://blog.csdn.net/qq_26891045/article/details/51888524
The least common multiple (LCM) of a set of positive integers is the smallest positive integer which is divisible by all the numbers in the set. For example, the LCM of 5, 7 and 15 is 105.
Input
Input will consist of multiple problem instances. The first line of the input will contain a single integer indicating the number of problem instances. Each instance will consist of a single line of the form m n1 n2 n3 … nm where m is the number of integers in the set and n1 … nm are the integers. All integers will be positive and lie within the range of a 32-bit integer.
Output
For each problem instance, output a single line containing the corresponding LCM. All results will lie in the range of a 32-bit integer.
Sample Input
2
3 5 7 15
6 4 10296 936 1287 792 1
Sample Output
105
10296

//change int to __int64
#include<iostream>
#include<stdio.h>
using namespace std;
int gcd(int a,int b)
{
    int r;
    if(a<b){
        r=a;
        a=b;
        b=r;
    }
    r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}
int lcm(int a,int b)//lcm*gcd==a*b
{
    return a*b/gcd(a,b);
}
int main()
{
    int n,i,a,b,m;
    cin >>n;
    for(i=0;i<n;i++){
        cin >> m;
        cin >> a;
        m=m-1;
        while(m--){
            cin >> b;
            a=lcm(a,b);
        }
        cout << a << endl;
    }
    return 0;
}

J - Ignatius and the Princess IV (memset)

#include <iostream>
#include <string.h>
using namespace std;
int main()
{
    int map[100000];
    int n,i,t,flag;
    while(cin >> n){
        memset(map,0,sizeof(map));
        for(i=0;i<n;i++){
            cin >> t;
            map[t]=map[t]+1;
            if(map[t]>n/2)
                flag=t;
        }
        cout << flag << endl;
    }
    return 0;
}

K - next_permutation

要用康托展开?8会,直接用轮子Next_permutation

#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
int main()
{
    int ls[1001];
    int n,m;
    while(cin>>n>>m)
    {
        int i;
        for(i=1;i<=n;i++)
            ls[i]=i;
        for(i=2;i<=m;i++)
            next_permutation(ls+1,ls+n+1);
        for(i=1;i<=n;i++){
            cout << ls[i];
            if(i!=n)
                cout<<" ";
        }
        cout << endl;
    }
    return 0;
}

L - Delta-wave(公式不会推)

https://blog.csdn.net/enjoying_science/article/details/38500755
公式不会推啊

X=(int)sqrt(n-1)+1;
Y= (n - (X-1)(X-1)+1)/2;
Z= (X
X - n)/2+1;

#include <iostream>
#include <cmath>
#include <string.h>
using namespace std;\
void calculate(int ls[3],int n)
{
    ls[0]=(int)sqrt(n-1)+1;
    int x;
    x=ls[0];
    ls[1]=(n-(x-1)*(x-1)+1)/2;
    ls[2]=(x*x-n)/2+1;
}
int main()
{
    int p1,p2;
    while(cin>>p1>>p2){
        int l1[3],l2[3];
        calculate(l1,p1);
        calculate(l2,p2);
        cout<<abs(l1[0]-l2[0])+abs(l1[1]-l2[1])+abs(l1[2]-l2[2])<<endl;
    }
    return 0;
}

M - Digital Roots

防止给的数字太大,因此用getchar来进行第一次加和

#include <iostream>
#include <cstdio>
using namespace std;
int one(int x)
{
    int ans=0;
    while(1){
        if(x<10)
            return x;
        while(x>0){
            ans+=x%10;
            x/=10;
        }
        x=ans;
        ans=0;
    }
}
int main()
{
    while(1)
    {
        int sum=0;
        char c;
        //the number may be very big
        while((c=getchar())!='\n')
            sum+=(c-'0');
        if(sum==0)
            break;
        cout<<one(sum)<<endl;
    }
    return 0;
}

N - Bullseye

#include<iostream>
using namespace std;
int score(double x,double y)
{
    double rr=x*x+y*y;
    if(rr<=9) return 100;
    else if(rr<=6*6) return 80;
    else if(rr<=9*9) return 60;
    else if(rr<=12*12) return 40;
    else if(rr<=15*15) return 20;
    else return 0;
}
int main()
{
    double a,b;
    int suma=0,sumb=0;
    for(int i=0;i<6;i++){
        cin >> a >> b;
        if(a==-100)
            break;
        if(i<3)
            suma+=score(a,b);
        else if(i<6)
            sumb+=score(a,b);
        if(i==5){//i+++ -> i=i+1
            i=-1;
            if(suma>sumb)
                cout<<"SCORE: "<<suma<<" to "<<sumb<<", PLAYER 1 WINS."<<endl;
            else if(sumb>suma)
                cout<<"SCORE: "<<suma<<" to "<<sumb<<", PLAYER 2 WINS."<<endl;
            else
                cout<<"SCORE: "<<suma<<" to "<<sumb<<", TIE."<<endl;
            suma=0;
            sumb=0;
        }
    }
    return 0;
}

O - Dirichlet’s Theorem on Arithmetic Progressions

提交过程中sqrt参数为int不给过,记得强转为double或float

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int prime(int x)
{
    int i;
    if(x==1)
        return 0;
    for(i=2;i<=sqrt(double(x));i++){
        if(x%i==0)
            return 0;
    }
    return 1;
}
int main()
{
    int a,d,n;
    while(cin>>a>>d>>n){
        if(n==0)
            break;
        if(prime(a))n--;
        while(n!=0){
            a+=d;
            if(prime(a))n--;
        }
        cout<<a<<endl;
    }
    return 0;
}

P - Reduced ID Numbers (不用memset就TE)

把mod函数里的check[300]={-1}改用memset就过了

#include <iostream>
#include <cmath>
#include <string.h>
using namespace std;
int find(int ls[],int e,int p)
{
    for(int i=0;i<=e;i++)
        if(p==ls[i])
            return 1;
    return 0;
}
int mod(int ls[],int k)
{
    int ans,i,check[300];//check[300]={-1};
    for(ans=1;;ans++){
        memset(check,-1,sizeof(check));//nothing here
        //int t=ls[0]%ans;   go wrong when the second and the third is the same
        for(i=0;i<k;i++){
            if(find(check,i,ls[i]%ans))
                break;
            check[i]=ls[i]%ans;
        }
        if(i==k)
            return ans;
    }
}
int main()
{
    int ls[300];
    int N;
    cin >> N;
    for(int qwe=0;qwe<N;qwe++)
    {
        int g;
        cin >> g;
        for(int i=0;i<g;i++){
            int t;
            cin >> t;
            ls[i]=t;
        }//stored in ls
        cout << mod(ls,g) << endl;
    }
    return 0;
}

Q-大数幂

下面是自己写的,怎么都过不去,难受的一p
java直接调包过就完事了
https://blog.csdn.net/u012340794/article/details/50544377

import java.util.*;
import java.math.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n;
		String r;
		while(sc.hasNext()){
			r = sc.next();
			n = sc.nextInt();
			BigDecimal bd = new BigDecimal(r);
			BigDecimal result = bd.pow(n);
			//BigDecimal:不可变的、任意精度的有符号十进制数
			
			r = result.stripTrailingZeros().toPlainString();
			//stripTrailingZeros():返回数值上等于此小数,但从该表示形式移除所有尾部零的 BigDecimal
			//toPlainString():将BigDecimal转换为字符串
			
			if(r.startsWith("0")){
				//去掉开头的0
				r=r.substring(1);
			}
			System.out.println(r);
		}
	}
}
#include <iostream>
#include <string>
#include <string.h>
using namespace std;
int zero(string s)
{
    if(s[0]=='0'&&s[2]=='0'&&s[3]=='0'&&s[4]=='0'&&s[5]=='0')
        return 1;
    else
        return 0;
}
int tn(char c)
{
    return c-'0';
}
char ttf(int x)
{
    return x+'0';
}
string change(string s)
{
    int pflag=1,bflag=-1,i;//123
    for(int i=0;i<int(s.length());i++)
        if(s[i]=='.'){
            pflag=0;
            break;
        }
    if(pflag)
        s=s+".0";
    //0002.0
    char str[100];
    int len=s.length();
    for(i=0;i<int(s.length());i++){
        str[i]=s[i];
        if(str[i]!='0'&&bflag==-1)
            bflag=i;
    }
    s="";
    if(str[bflag]=='.')
        s="0";
    for(i=bflag;i<len;i++)
        s+=str[i];
    for(i=int(s.length())-1;i<5;i++)
        s+='0';
    return s;
}
string BNMultipy(string num1,string num2)
{
    int len1=num1.length(),len2=num2.length();
    int fans[1000],ans[1000],i,j,flag;
    string anss="";
    memset(ans,0,sizeof(ans));
    memset(fans,0,sizeof(fans));
    for(i=len2-1,flag=999;i>-1;i--,flag--){
        int tem,f=flag;
        for(j=len1-1;j>-1;j--){
            tem=tn(num2[i])*tn(num1[j]);
            fans[f--]+=tem;
        }
    }
    int carry=0;
    for(i=999;i>-1;i--){
        ans[i]+=(carry+fans[i])%10;
        carry=(carry+fans[i])/10;//carry=fans[i]/10;
    }
    int yes=0;
    for(i=0;i<1000;i++){
        if(yes)
            anss+=ttf(ans[i]);
        else{
            if(ans[i]!=0)
                anss+=ttf(ans[i]),yes=1;
        }
    }
    return anss;
}
int main()
{
    string s;
    int n;
    while(cin>>s>>n){
        s=change(s);
        int i,point;//有可能没有小数点
        if(zero(s)){
            cout<<0<<endl;
            continue;
        }
        else if(n==0){
            cout<<1<<endl;
            continue;
        }
        if(n==1&&s[0]=='0'){
            int oo;
            for(i=5;i>-1;i--)
                if(s[i]!='0'){
                    oo=i;
                    break;
                }
            for(i=1;i<=oo;i++)
                cout<<s[i];
            cout<<endl;
            continue;
        }
        string a="",ans="";
        for(i=0;i<6;i++){//i<int(s.length()) is wrong
            if(s[i]=='.')
                point=5-i;
            else
                a+=s[i];
        }
        string b=a;
        point=point*n;
        for(i=0;i<n-1;i++)
            a=BNMultipy(a,b);
        int len=a.length();
        for(i=0;i<len;i++){
            if(i==len-point&&len>=point)
                ans+=".",ans+=a[i];
            else
                ans+=a[i];
        }
        len=ans.length();
        for(i=len-1;;i--){
            if(ans[i]=='0'){
                ans[i]='\0';
                if(ans[i-1]=='.')
                    ans[i-1]='\0';
            }
            else
                break;
        }
        if(s[0]=='0'){
            cout<<".";
            for(i=0;i<4*n-int(ans.length());i++)
                cout<<"0";
        }
        cout<<ans<<endl;
    }
    return 0;
}

R - Joseph

此题打表过,否则TE
好人的范围不会变,去除的坏人为5678中的7,则坏人又变为567

#include<iostream>
#include<string.h>
using namespace std;
/*----------------------打表代码---------------------------*/
int da_biao(void)
{
    int k,cnt,i;
    while(cin>>k)
    {
        if(!k)break;
        int ans=1,flag;
        while(ans++){
            int p=1;
            flag=0;
            cnt=2*k;
            for(i=1;i<=k;i++){
                int t=(p+ans-1)%cnt;
                if(t>0&&t<=k){
                    flag=1;
                    break;
                }
                cnt--;
                if(t==0)//如果去掉了最后一个人,那么下次从第一个人开始
                    p=1;
                else//否则上个被杀的人的编号就是下次开始的编号
                    p=t;
            }
            if(flag)continue;
            else break;
        }
        cout<<ans<<endl;
    }
    return 0;
}
/*----------------------打表代码---------------------------*/
int main()
{
    int k;
    int ls[14]={2,7,5,30,169,441,1872,7632,1740,93313,459901,1358657,2504881};
    while(cin >> k){
        if(k==0)
            break;
        cout<<ls[k-1]<<endl;
    }
    return 0;
}

S - Counterfeit Dollar

https://blog.csdn.net/qq_41045071/article/details/81740569
用枚举解决,每个假设都过一遍

#include <iostream>
#include <string.h>
#include <string>
using namespace std;
string s1[3],s2[3],s3[3];
int statu[12],k;
int judge()
{
    int i;
    for(i=0;i<3;i++){//3遍必须判断完才能确认
        int j;
        int left=0,right=0;
        for(j=0;j<s1[i].length();j++)
            left+=statu[s1[i][j]-'A'];
        for(j=0;j<s2[i].length();j++)
            right+=statu[s2[i][j]-'A'];
        if(left>right&&s3[i]!="up")
            return 0;
        if(left<right&&s3[i]!="down")
            return 0;
        if(left==right&&s3[i]!="even")
            return 0;
    }
    return 1;//3次判断没有问题时才返回true
}
int main()
{
    int n;
    cin>>n;
    while(n--){
        for(int i=0;i<3;i++)
            cin>>s1[i]>>s2[i]>>s3[i];
        memset(statu,0,sizeof(statu));
        for(k=0;k<12;k++){
            statu[k]=1;
            if(judge())break;
            statu[k]=-1;
            if(judge())break;
            statu[k]=0;
        }
        string a;
        if(statu[k]>0)a="heavy";
        else if(statu[k]<0)a="light";
        char ans=k+'A';
        cout<<ans<<" is the counterfeit coin and it is "<<a<<"."<<endl;
    }
    return 0;
}

U - Long Distance Racing

#include<iostream>
using namespace std;
char road[100001];
int N,T,U,F,D;
int main()
{
    int cnt=0;
    cin>>N>>T>>U>>F>>D;
    for(int i=0;i<T;i++)
        cin>>road[i];
    int sum=0;
    for(;;cnt++){
        char d=road[cnt];
        if(d=='f')
            sum+=2*F;
        else
            sum+=D+U;
        if(sum>N)
            break;
    }
    cout<<cnt<<endl;
    return 0;
}

V - The Fun Number System

自己强制模拟是WA过不了…果然是太菜了

//WA
#include <iostream>
#include <string.h>
#include <string>
using namespace std;
__int64 num[64],numt[64];
__int64 k,nn,i;
__int64 poww(__int64 n)
{
    __int64 ans=1;
    for(i=0;i<n;i++)
        ans*=2;
    return ans;
}
int judge()
{
    __int64 tt=-1,m,n,q;
    __int64 ans=0;
    string res="";
    memset(numt,0,sizeof(num));
    for(m=0;m<k-1;m++){
        numt[tt++]=1;
        for(n=tt;n<k;n++){
            ans=0;
            numt[n]=1;
            for(q=0;q<k;q++)
                ans+=poww(k-q-1)*numt[q]*num[q];
            if(ans==nn)
                return 1;
            numt[n]=0;
        }
    }
    return 0;
}
int main()
{
    int N;
    cin>>N;
    while(N--){
        string t,ans="";
        cin>>k>>t>>nn;
        for(i=0;i<k;i++)
            num[i]=(t[i]=='p'?1:-1);
        if(judge()){
            for(i=0;i<k;i++)
                cout<<numt[i];
            cout<<endl;
        }
        else
            cout<<"Impossible"<<endl;
    }
    return 0;
}

W - The Circumference of the Circle

R=abc/4/S a,b,c为边长,S为三角形面积

#include<iostream>
#include<cmath>
#include<cstdio>
#define PI 3.141592653589793
using namespace std;
int main()
{
    double x1,x2,x3,y1,y2,y3;
    while(cin>>x1>>y1>>x2>>y2>>x3>>y3){
        double S=((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1))/2;
        double abc=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))\
                   *sqrt((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1))\
                   *sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3));
        double R=abc/4/S;
        printf("%.2lf\n",fabs(2*PI*R));
    }
    return 0;
}

X - Specialized Four-Digit Numbers

掌握进制转化的基本原理,设计digits函数转任何进制数字digits之和

#include <iostream>
using namespace std;
int digits(int n,int x)
{
    int rest,sum=0;
    while(n>0){
        rest=n%x;
        sum+=rest;
        n/=x;
    }
    return sum;
}
int main()
{
    for(int i=2992;i<=9999;i++)
        if(digits(i,10)==digits(i,12)&&digits(i,10)==digits(i,16))
            cout<<i<<endl;
    return 0;
}

Y - A == B ? (数组开小导致超时)

//TE
#include<stdio.h>
#include<string.h>
void f(char *a)
{
    int i,p=0;
    for(i=0;i<strlen(a);i++){
        if(a[i]=='.'){
            p=i;
            break;
        }
    }
    if(p){
        for(i=strlen(a)-1;i>p;i--){
            if(a[i]=='0')
                a[i]='\0';
            else
                break;
        }
        if(p==i){//the situation is "4."
            a[p]='\0';//change "4." to "4"
        }
    }
}
int main()
{
    char a[100000]={0},b[100000]={0}; //char a[200],b[200];导致TE
    while(scanf("%s%s",a,b)!=EOF){
        f(a),f(b);
        if(strcmp(a,b)==0)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}
//TE

Z - A + B Problem II(大数加法)

注意输出是相邻之间有空行

sample out
Case 1:
1 + 2 = 3

Case 2:
112233445566778899 + 998877665544332211 = 1111111111111111110

#include <iostream>
#include <string>
#include <string.h>
using namespace std;
int max(int a,int b)
{
    return a>b?a:b;
}
int change(char c)
{
    int i;
    char s[]={'0','1','2','3','4','5','6','7','8','9'};
    for(i=0;i<10;i++){
        if(c==s[i])
            break;
    }
    return i;
}
int main()
{
    int na[1001]={0},nb[1001]={0},ns[1001]={0};
    int n,nn,len,salen,sblen;
    string sa,sb;
    cin >> n;
    for(nn=0;nn<n;nn++)
    {
        memset(na,0,sizeof(na));
        memset(nb,0,sizeof(nb));
        memset(nb,0,sizeof(nb));
        cin >> sa >> sb;
        salen=sa.length();
        sblen=sb.length();
        len=max(salen,sblen);
        int j=1000,i;
        for(i=salen-1;i>=0;i--)
            na[j--]=change(sa[i]);//na[j--]=sa[i]-'0'
        j=1000;
        for(i=sblen-1;i>=0;i--)
            nb[j--]=change(sb[i]);//nb[j--]=sb[i]-'0'
        int unit,buf=0,sum;
        for(i=1000;i>=1001-len-1;i--){//i=len-1 is wrong
            sum=na[i]+nb[i]+buf;
            unit=sum%10;
            ns[i]=unit;
            buf=sum/10;
        }
        cout << "Case " << nn+1 << ":" << endl;
        cout << sa << " + " << sb << " = ";
        if(buf)cout<<buf;
        for(i=1001-len;i<1001;i++)
            cout<<ns[i];
        cout<<endl;
        if(nn!=n-1)
            cout<<endl;
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
东南亚位于我国倡导推进的“一带一路”海陆交汇地带,作为当今全球发展最为迅速的地区之一,近年来区域内生产总值实现了显著且稳定的增长。根据东盟主要经济体公布的最新数据,印度尼西亚2023年国内生产总值(GDP)增长5.05%;越南2023年经济增长5.05%;马来西亚2023年经济增速为3.7%;泰国2023年经济增长1.9%;新加坡2023年经济增长1.1%;柬埔寨2023年经济增速预计为5.6%。 东盟国家在“一带一路”沿线国家中的总体GDP经济规模、贸易总额与国外直接投资均为最大,因此有着举足轻重的地位和作用。当前,东盟与中国已互相成为双方最大的交易伙伴。中国-东盟贸易总额已从2013年的443亿元增长至 2023年合计超逾6.4万亿元,占中国外贸总值的15.4%。在过去20余年中,东盟国家不断在全球多变的格局里面临挑战并寻求机遇。2023东盟国家主要经济体受到国内消费、国外投资、货币政策、旅游业复苏、和大宗商品出口价企稳等方面的提振,经济显现出稳步增长态势和强韧性的潜能。 本调研报告旨在深度挖掘东南亚市场的增长潜力与发展机会,分析东南亚市场竞争态势、销售模式、客户偏好、整体市场营商环境,为国内企业出海开展业务提供客观参考意见。 本文核心内容: 市场空间:全球行业市场空间、东南亚市场发展空间。 竞争态势:全球份额,东南亚市场企业份额。 销售模式:东南亚市场销售模式、本地代理商 客户情况:东南亚本地客户及偏好分析 营商环境:东南亚营商环境分析 本文纳入的企业包括国外及印尼本土企业,以及相关上下游企业等,部分名单 QYResearch是全球知名的大型咨询公司,行业涵盖各高科技行业产业链细分市场,横跨如半导体产业链(半导体设备及零部件、半导体材料、集成电路、制造、封测、分立器件、传感器、光电器件)、光伏产业链(设备、硅料/硅片、电池片、组件、辅料支架、逆变器、电站终端)、新能源汽车产业链(动力电池及材料、电驱电控、汽车半导体/电子、整车、充电桩)、通信产业链(通信系统设备、终端设备、电子元器件、射频前端、光模块、4G/5G/6G、宽带、IoT、数字经济、AI)、先进材料产业链(金属材料、高分子材料、陶瓷材料、纳米材料等)、机械制造产业链(数控机床、工程机械、电气机械、3C自动化、工业机器人、激光、工控、无人机)、食品药品、医疗器械、农业等。邮箱:market@qyresearch.com

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值