在本文中,我们将详细介绍[Swift]LeetCode620.有趣的电影|NotBoringMovies的各个方面,并为您提供关于超有趣的电影的相关解答,同时,我们也将为您带来关于!!〜(notnot
在本文中,我们将详细介绍[Swift]LeetCode620. 有趣的电影 | Not Boring Movies的各个方面,并为您提供关于超有趣的电影的相关解答,同时,我们也将为您带来关于!!〜(not not tilde/bang bang tilde)如何改变“contains/included” Array方法调用的结果?、620. 有趣的电影、A Boring Problem UVALive - 7676、calico/node is not ready: BIRD is not ready: BGP not established的有用知识。
本文目录一览:- [Swift]LeetCode620. 有趣的电影 | Not Boring Movies(超有趣的电影)
- !!〜(not not tilde/bang bang tilde)如何改变“contains/included” Array方法调用的结果?
- 620. 有趣的电影
- A Boring Problem UVALive - 7676
- calico/node is not ready: BIRD is not ready: BGP not established
[Swift]LeetCode620. 有趣的电影 | Not Boring Movies(超有趣的电影)
SQL架构
1 Create table If Not Exists cinema (id int,movie varchar(255),description varchar(255),rating float(2,1)) 2 Truncate table cinema 3 insert into cinema (id,movie,description,rating) values (‘1‘,‘War‘,‘great 3D‘,‘8.9‘) 4 insert into cinema (id,rating) values (‘2‘,‘Science‘,‘fiction‘,‘8.5‘) 5 insert into cinema (id,rating) values (‘3‘,‘irish‘,‘boring‘,‘6.2‘) 6 insert into cinema (id,rating) values (‘4‘,‘Ice song‘,‘Fantacy‘,‘8.6‘) 7 insert into cinema (id,rating) values (‘5‘,‘House card‘,‘Interesting‘,‘9.1‘)
X city opened a new cinema,many people would like to go to this cinema. The cinema also gives out a poster indicating the movies’ ratings and descriptions.
Please write a sql query to output movies with an odd numbered ID and a description that is not ‘boring‘. Order the result by rating.
For example,table cinema
:
+---------+-----------+--------------+-----------+ | id | movie | description | rating | +---------+-----------+--------------+-----------+ | 1 | War | great 3D | 8.9 | | 2 | Science | fiction | 8.5 | | 3 | irish | boring | 6.2 | | 4 | Ice song | Fantacy | 8.6 | | 5 | House card| Interesting| 9.1 | +---------+-----------+--------------+-----------+
For the example above,the output should be:
+---------+-----------+--------------+-----------+ | id | movie | description | rating | +---------+-----------+--------------+-----------+ | 5 | House card| Interesting| 9.1 | | 1 | War | great 3D | 8.9 | +---------+-----------+--------------+-----------+
某城市开了一家新的电影院,吸引了很多人过来看电影。该电影院特别注意用户体验,专门有个 LED显示板做电影推荐,上面公布着影评和相关电影描述。
作为该电影院的信息部主管,您需要编写一个 SQL查询,找出所有影片描述为非 boring
(不无聊) 的并且 id 为奇数 的影片,结果请按等级 rating
排列。
例如,下表 cinema
:
+---------+-----------+--------------+-----------+ | id | movie | description | rating | +---------+-----------+--------------+-----------+ | 1 | War | great 3D | 8.9 | | 2 | Science | fiction | 8.5 | | 3 | irish | boring | 6.2 | | 4 | Ice song | Fantacy | 8.6 | | 5 | House card| Interesting| 9.1 | +---------+-----------+--------------+-----------+
对于上面的例子,则正确的输出是为:
+---------+-----------+--------------+-----------+ | id | movie | description | rating | +---------+-----------+--------------+-----------+ | 5 | House card| Interesting| 9.1 | | 1 | War | great 3D | 8.9 | +---------+-----------+--------------+-----------+
108ms
1 # Write your MysqL query statement below 2 select id,rating 3 from cinema 4 where mod(id,2) = 1 AND description <> "boring" 5 order by rating desc
109ms
1 # Write your MysqL query statement below 2 select * from cinema where description != ‘boring‘ and id % 2 = 1 order by rating desc
110ms
1 # Write your MysqL query statement below 2 select a.* from cinema as a where mod(a.id,2)=1 and a.description != ‘boring‘ order by rating desc;
111ms
1 # Write your MysqL query statement below 2 select * 3 from cinema 4 where not description = "boring" and mod(id,2) = 1 5 order by rating desc
115ms
1 # Write your MysqL query statement below 2 select * from cinema 3 where id%2 <> 0 4 and description not like "%boring%" 5 order by rating desc
!!〜(not not tilde/bang bang tilde)如何改变“contains/included” Array方法调用的结果?
如果您在此处的jQueryinArray
页面上阅读了注释,则会有一个有趣的声明:
!!~jQuery.inArray(elm, arr)
现在,我相信双感叹号会将结果转换为typeboolean
,其值为true
。我不明白的是,~
在所有这些操作中,tilde()运算符的用途是什么?
var arr = ["one", "two", "three"];if (jQuery.inArray("one", arr) > -1) { alert("Found"); }
重构if
语句:
if (!!~jQuery.inArray("one", arr)) { alert("Found"); }
分解:
jQuery.inArray("one", arr) // 0~jQuery.inArray("one", arr) // -1 (why?)!~jQuery.inArray("one", arr) // false!!~jQuery.inArray("one", arr) // true
我还注意到,如果将波浪号放在前面,结果是-2
。
~!!~jQuery.inArray("one", arr) // -2
我不明白这里的波浪符号的目的。有人可以解释一下还是将我指向资源?
答案1
小编典典波浪号运算符实际上根本不是jQuery的一部分-在JavaScript本身中是按位NOT运算符。
参见 The Great Mystery of the Tilde(~). 。
您在实验中得到了奇怪的数字,因为您正在对整数执行按位逻辑运算(就我所知,整数可能存储为二进制补码或类似的数字…)
_二进制补码_说明了如何用二进制表示数字。我想我是对的。
答案2
小编典典!!~expr
评估false
何时expr
为-1
否则true
。与相同expr != -1
,只有断线*
之所以有效,是因为JavaScript按位运算将操作数转换为二进制补码形式的32位有符号整数。因此!!~-1
评估如下:
-1 = 1111 1111 1111 1111 1111 1111 1111 1111b // two''s complement representation of -1 ~-1 = 0000 0000 0000 0000 0000 0000 0000 0000b // ~ is bitwise not (invert all bits) !0 = true // ! is logical not (true for falsy)!true = false // duh
以外的值-1
将至少一位设置为零;否则为0
。反转它会产生一个真实的价值;将!
运算符两次应用于真实值会返回布尔值true。
当与一起使用时.indexOf()
,我们只想检查结果是否为-1
:
!!~"abc".indexOf("d") // indexOf() returns -1, the expression evaluates to false!!~"abc".indexOf("a") // indexOf() returns 0, the expression evaluates to true!!~"abc".indexOf("b") // indexOf() returns 1, the expression evaluates to true
!!~8589934591
评估为假,因此厌恶无法可靠地用于测试-1
。
答案3
小编典典您有时会~在前面看到一个特定的原因$.inArray
。
基本上,
~$.inArray("foo", bar)
是一种较短的方法
$.inArray("foo", bar) !== -1
$.inArray
如果找到第一个参数,则返回数组中该项的索引,如果找不到第一个参数,则返回-1。这意味着,如果要查找“此值在数组中吗?”的布尔值,则不能进行布尔值比较,因为-1是真实值,并且$ .inArray返回0(虚假值) ),则表示其实际位于数组的第一个元素中。
应用~
按位运算符导致-1
变为0
,并使0
变为-1
。因此,在数组中找不到该值并应用按位NOT不会得出虚假的值(0),其他所有值将返回非0的数字,并表示真实结果。
if (~$.inArray("foo", ["foo",2,3])) { // Will run}
并且它将按预期工作。
620. 有趣的电影
某城市开了一家新的电影院,吸引了很多人过来看电影。该电影院特别注意用户体验,专门有个 LED 显示板做电影推荐,上面公布着影评和相关电影描述。
作为该电影院的信息部主管,您需要编写一个 SQL 查询,找出所有影片描述为非 boring
(不无聊) 的并且 id 为奇数 的影片,结果请按等级 rating
排列。
例如,下表 cinema
:
+---------+-----------+--------------+-----------+
| id | movie | description | rating |
+---------+-----------+--------------+-----------+
| 1 | War | great 3D | 8.9 |
| 2 | Science | fiction | 8.5 |
| 3 | irish | boring | 6.2 |
| 4 | Ice song | Fantacy | 8.6 |
| 5 | House card| Interesting| 9.1 |
+---------+-----------+--------------+-----------+
对于上面的例子,则正确的输出是为:
+---------+-----------+--------------+-----------+
| id | movie | description | rating |
+---------+-----------+--------------+-----------+
| 5 | House card| Interesting| 9.1 |
| 1 | War | great 3D | 8.9 |
+---------+-----------+--------------+-----------+
1 # Write your MySQL query statement below
2 select id,movie,description,rating
3 from cinema
4 where description != ''boring'' and mod(id,2) = 1
5 order by rating desc
A Boring Problem UVALive - 7676
16年北京现场赛的题,全场过的队30+。
初看只知道 O(N^2logK)的暴力,以为是什么变换。
仔细发现活用 二项式定理 就行。


1 #include <bits/stdc++.h>
2 using namespace std;
3 #define fst first
4 #define scd second
5 #define pb(x) push_back((x))
6 #define mkp(x,y) make_pair((x),(y))
7 #define ist(x) insert((x))
8 typedef long long ll;
9 typedef pair<int ,int > pii;
10 typedef pair<ll ,ll > pll;
11 typedef vector< int > vi;
12 ll gcd(ll a,ll b){ return b==0?a:gcd(b,a%b);}
13 ll qPow(ll a,ll b,ll mod){ ll ret=1ll;while(b){ if(b&1) ret=ret*a%mod;a=a*a%mod;b>>=1;} return ret; }
14
15 const ll mod=1e9+7;
16 const int maxn=5e4+4;
17 ll P[maxn][128]; // P[i][k] 代表 前i个数字之和的k次方
18 ll Pre[maxn][128];// Pre[i][k] 代表 前i个P[i][k]的和
19 ll F[128],INV[128];
20 char raw[maxn];
21 int N,K;
22
23 void init(){
24 P[0][0]=1;
25 for(int i=1;i<=N;++i){
26 P[i][0]=1;
27 P[i][1]=(P[i-1][1]+raw[i-1]-''0'')%mod;
28 for(int j=2;j<=K;++j)
29 P[i][j]=P[i][j-1]*P[i][1]%mod;
30 }
31
32 Pre[0][0]=1;// 0^0 =1
33 for(int j=0;j<=K;++j){
34 for(int i=1;i<=N;++i)
35 Pre[i][j]=(Pre[i-1][j]+P[i][j])%mod;
36 }
37 }
38
39 ll getC(int i,int j){
40 if(j==0) return 1ll;
41 return F[i]*INV[i-j]%mod*INV[j]%mod;
42 }
43
44 int main(){
45
46 F[0]=1ll;
47 for(ll i=1;i<=100;++i)
48 F[i]=F[i-1]*i%mod;
49 INV[100]=qPow(F[100],mod-2,mod);
50 for(ll i=99;i>=0;i--)
51 INV[i]=(i+1)*INV[i+1]%mod;
52
53 int Tests;
54 scanf("%d",&Tests);
55 while(Tests--){
56 scanf("%d%d",&N,&K);
57 scanf("%s",raw);
58 init();
59 ll ans;
60 for(int i=1;i<=N;++i){
61 ans=0ll;
62 for(int j=0;j<=K;++j){
63 if(j&1)
64 ans=(ans-getC(K,j)*P[i][K-j]%mod*Pre[i-1][j]%mod+mod)%mod;
65 else
66 ans=(ans+getC(K,j)*P[i][K-j]%mod*Pre[i-1][j]%mod)%mod;
67 }
68 printf("%lld%c",ans,i==N?''\n'':'' '');
69 }
70 }
71 return 0;
72 }
(代码写的常数有点大,应该是mod多了,,,
calico/node is not ready: BIRD is not ready: BGP not established
calico/node is not ready: BIRD is not ready: BGP not established
关于[Swift]LeetCode620. 有趣的电影 | Not Boring Movies和超有趣的电影的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于!!〜(not not tilde/bang bang tilde)如何改变“contains/included” Array方法调用的结果?、620. 有趣的电影、A Boring Problem UVALive - 7676、calico/node is not ready: BIRD is not ready: BGP not established的相关知识,请在本站寻找。
本文标签: