e273: 微分入門課

e273: 微分入門課

題目連結:e273: 微分入門課

題意:

求一個多項式函數 f(x) 對 x 微分的結果

解法:

C++:


測資很多,需優化I/O。

time:0.1s(90ms)
通過檢測

通過檢測

嗚嗚嗚明明測資一樣時間卻不一樣
memory used:1.1MB
code:

  1. #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
  2. #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  3. #pragma comment(linker, "/stack:200000000")
  4. #include<ios>
  5. char buf[1<<20],*p1=buf,*p2=buf;
  6. inline int getc(){
  7. return p1==p2&&(p2=(p1=buf)+fread_unlocked(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++;
  8. }
  9. inline void write(uint_fast16_t x){
  10. static int stk[6],top=0;
  11. int *ptr;
  12. ptr=&stk[0];
  13. while(x){*ptr=x%10;x/=10;ptr++;}
  14. ptr--;
  15. while(ptr>=(&stk[0])){putchar_unlocked(*ptr+'0');ptr--;}
  16. }
  17. inline int read(){
  18. uint_fast16_t ret=0;
  19. char ch=getc();
  20. while(ch>='0'&&ch<='9')
  21. ret=(ret<<1)+(ret<<3)+ch-'0',ch=getc();
  22. return ret;
  23. }
  24. int main(){
  25. uint_fast16_t a;
  26. while(a=read()){
  27. for(int i=a-1;i>=1;--i){
  28. write(read()*i);
  29. putchar_unlocked(' ');
  30. }
  31. redn();
  32. if(a==1)putchar_unlocked('0');
  33. putchar_unlocked('\n');
  34. }
  35. }

Python:

建表代替過慢的乘法即可AC

time:1.9s
memory used:6.8MB
code:

  1. from sys import stdin
  2. from sys import stdout
  3. = {}
  4. for i in range(1,50): d[str(i)] = [str(i*k) for k in range(0,1000)]
  5. for s in stdin:
  6.     n = int(s)
  7.     if(== 1):
  8.         f = stdin.readline()
  9.         stdout.write('0\n')
  10.     else:
  11.         f = [d[i][j] for i, j in zip(stdin.readline().split(),range(n-1,0,-1))]
  12.         stdout.write(' '.join(f)+'\n')


本人的分享到此結束

若有更好的想法或建議,請在留言區留言喔

Comments

Popular Posts