zoukankan      html  css  js  c++  java
  • 2021“MINIEYE杯”中国大学生算法设计超级联赛(4)1001. Calculus(思维)

    Problem Description

    This summer, ZXyang became so tired when doing the problems of Multi-University contests. So he decided to attend the Unified National Graduate Entrance Examination. This day, he sees a problem of series.

    Let S(x) be a function with x as the independent variable. S(x) can be represented by the formula as follow.

    f(x)=∑i=1nfi(x)

    S(x)=∑j=1xf(j)

    fi(x) is a function with x as the independent variable. Furthermore. fi(x) belongs to the function set F.

    F={C,Cx,Csinx,Ccosx,Csinx,Ccosx,Cx,Cx}

    C is a constant integer ranging from 0 to 109.

    ZXyang wonders if S(x) is convergent. S(x) is convergent if and only if limx→∞S(x)=c, where c is a constant.

    Input

    The first line of input contains a single integer t (1≤t≤104) --- the number of test cases.

    The first and the only line of each test case contains a single string s (1≤|s|≤100), indicating the formula of f(x). Fraction is presented as a/b. Cx is presented as C^x. It's guaranteed that the constant C won't be left out when C=1. f(x) consists of functions from F connected with +.

    Output

    For each test case, print YES in one line if S(x) is a convergent sequence, or print NO in one line if not.

    Sample Input

    2
    1sinx+0cosx+3x+6/sinx
    0
    

    Sample Output

    NO
    YES
    

    签到题,这些级数都是不收敛的,因此必须每一项的系数都是0才可以。特别注意常数项的情况。至于代码可以先把每一项拆开判断。

    #include <bits/stdc++.h>
    using namespace std;
    int main() {
    	int t;
    	cin >> t;
    	while(t--) {
    		string s;
    		cin >> s;
    		int len = s.size();
    		int lst = 0;
    		vector<string> v;
    		for(int i = 0; i <= len; i++) {
    			if(i == len || s[i] == '+') {
    				v.push_back(s.substr(lst, i - lst));
    				lst = i + 1;
    			}
    		}
    		bool flag = 1;
    		for(auto x : v) {
    
    			int pos = x.find("/");
    			if(pos != x.npos) {
    				if(!(pos == 1 && x[0] == '0')) {
    					flag = 0;
    					break;
    				}
    				continue;
    			}
    
    			int pos1 = x.find("^");
    			if(pos1 != x.npos) {
    				if(!(pos1 == 1 && (x[0] == '0' || x[0] == '1'))) {
    					// cout << "fuck";
    					flag = 0;
    					break;
    				}
    				continue;
    			}
    			int pos2 = x.find("sin");
    			if(pos2 != x.npos) {
    				if(!(pos2 == 1 && x[0] == '0')) {
    					flag = 0;
    					break;
    				}
    				continue;
    			}
    			int pos3 = x.find("cos");
    			if(pos3 != x.npos) {
    				if(!(pos3 == 1 && x[0] == '0')) {
    					flag = 0;
    					break;
    				}
    				continue;
    			}
    			int pos4 = x.find("x");
    			if(pos4 != x.npos) {
    				if(!(pos4 == 1 && x[0] == '0')) {
    					flag = 0;
    					break;
    				}
    				continue;
    			}
    			if(x.size() > 1 || x[0] != '0') {
    				flag = 0;
    				break;
    			}
    		}
    		if(flag) puts("YES");
    		else puts("NO");
    	}
    	return 0;
    }
    
  • 相关阅读:
    软件概要设计
    项目文件-搭建工程
    select标签中设置只读几种解决方案
    PHP ob缓冲区函数的使用
    laravel笔记
    ubuntu系统更新命令
    RBAC权限控制系统
    laravel 数据库获取值的常用方法
    php中获取数据 php://input、$_POST与$GLOBALS['HTTP_RAW_POST_DATA']三者的区别
    php 文件上传 $_FILES 错误码
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/15076079.html
Copyright © 2011-2022 走看看