水题堆2.F - "红色病毒"问题(看崩溃

#include <stdio.h>
#include <math.h>

int main()
{
    long long m;
    int n,i;
    int s[] = {4, 8,16,32,64,28,56,12,24,48,
    96,92,84,68,36,72,44,88,76,52};
    //s[1]=2;
    /*for(i=2;i<=25;i++){
        k=k*2;
        s[i]=k*k+k;
    }*/
    while(1){
        scanf("%d",&n);
        if(n==0)break;
        for(i=1;i<=n;i++){
            scanf("%lld",&m);
            //m=(m-2)%20+2;
            //printf("Case %d: ",i);
            //printf("%lld\n",s[m]%100);
            printf("Case %d: %d\n",i,m<3?(m<2?2:6):(s[(2*m-4)%20]+s[(m-3)%20])%100);
        }
        printf("\n");
    }
    return 0;
}

这道题看了别人的思路,用的是递推的办法(数论看不懂= =

如果没有限制,ABCD组成长度为n的字符串,应该有4^n种,因为有限制,所以分四组来讨论

1.用f[n][0]表示长度为n,A,C都出现偶数次的情况

2.用f[n][1]表示长度为n,A出现奇数次而C出现偶数次的情况

3.用f[n][2]表示长度为n,C出现奇数次而A出现偶数次的情况

4.用f[n][3]表示长度为n,A,C都出现奇数次的情况

现在分析每种情况

1.f[n][0]

(1)在f[n-1][0]的末尾加B或D(这里我刚开始认为应该是在任意位置插入B,D,应该是2*n*f[n][0],但是后来一想,这样的话会造成重复)

(2)在f[n-1][1]的末尾加A

(3)在f[n-1][2]的末尾加C

所以f[n][0]=2*f[n-1][0]+f[n-1][1]+f[n-1][2];

2.f[n][1]

   与1同理 可得f[n][1]=2*f[n-1][1]+f[n-1][0]+f[n-1][3];

3.f[n][2]

   同理可得 f[n][2]=2*f[n-1][2]+f[n-1][0]+f[n-1][3];

4.f[n][3]

    f[n][3]=2*f[n-1][3]+f[n-1][1]+f[n-1][2];

又有f[1][0]=2,f[1][1]=1,f[1][2]=1,f[1][3]=0;

则f[n][1]=f[n][2]

f[n][0]+f[n][3]=f[n][1]+f[n][2],f[n][0]+f[n][1]+f[n][2]+f[n][3]=4^n

所以f[n][0]=2*f[n-1][0]+f[n-1][1]+f[n-1][2]=2*f[n-1][0]+2 *4^(n-2)

一层层迭代下去,得

       f[n][0]=2^n+2^(n-1)+......+2^(2n-3)=4^(n-1)+2^(n-1);

因为2^n最后两位是有规律的,所以f[n][0]最后两位也是有规律的

2^22最后两位是4,与2^2相同,这就进入了一个循环,所以结果就在22个数字里面

package com.github.catvod.spider; import android.content.Context; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.github.catvod.bean.Class; import com.github.catvod.bean.Filter; import com.github.catvod.bean.Result; import com.github.catvod.bean.Vod; import com.github.catvod.crawler.Spider; import com.github.catvod.net.OkHttp; import com.github.catvod.utils.Notify; import com.github.catvod.utils.Util; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; import java.net.URLEncoder; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; public class CeChi extends Spider { private static String siteUrl = &quot;https://cechi16.com&quot;; private static String cateUrl = &quot;https://gda52.quelingfei.com/getsortdata_all_z.php?&quot;; private static String searchUrl = &quot;https://v2.quelingfei.com/ssszz.php?q=&quot;; private Map<String, String> getHeader() { Map<String, String> header = new HashMap<>(); header.put(&quot;User-Agent&quot;, Util.CHROME); return header; } @Override public void init(Context context, String extend) throws Exception { super.init(context, extend); if (!extend.isEmpty()) { siteUrl = extend; } } @Override public String homeContent(boolean filter) throws Exception { List<Class> classes = new ArrayList<>(); List<String> typeIds = Arrays.asList(&quot;tv&quot;, &quot;mov&quot;, &quot;acg&quot;, &quot;zongyi&quot;); List<String> typeNames = Arrays.asList(&quot;电视剧&quot;, &quot;电影&quot;, &quot;动漫&quot;, &quot;综艺&quot;); for (int i = 0; i < typeIds.size(); i++) classes.add(new Class(typeIds.get(i), typeNames.get(i))); Document doc = Jsoup.parse(OkHttp.string(siteUrl, getHeader())); List<Vod> list = new ArrayList<>(); for (Element li : doc.select(&quot;div.index-list-l&quot;).select(&quot;ul&quot;).select(&quot;li&quot;)) { String vid = siteUrl + &quot;/&quot; + li.select(&quot;a.li-hv&quot;).attr(&quot;href&quot;); String name = li.select(&quot;a.li-hv&quot;).attr(&quot;title&quot;); String pic = li.select(&quot;a.li-hv img&quot;).attr(&quot;data-original&quot;); String remark = li.select(&quot;.name&quot;).text(); list.add(new Vod(vid, name, pic, remark)); } LinkedHashMap<String, List<Filter>> filters = new LinkedHashMap(); for (int i = 0; i < typeIds.size(); i++) { String typeId = typeIds.get(i); String filterUrl = siteUrl + String.format(&quot;/%s/0/0/all/1.html&quot;, typeId); Document filterDoc = Jsoup.parse(OkHttp.string(filterUrl, getHeader())); List<Filter> filterTemp = new ArrayList<>(); for (Element dl : filterDoc.select(&quot;div.sy&quot;).eq(0).select(&quot;dl&quot;)) { String key = dl.select(&quot;dt&quot;).eq(0).text().trim().replace(&quot;:&quot;,&quot;&quot;); String name = dl.select(&quot;dt&quot;).eq(0).text().trim().replace(&quot;:&quot;,&quot;&quot;); List<Filter.Value> filterValues = new ArrayList<>(); for (Element a : dl.select(&quot;dd&quot;).select(&quot;a&quot;)) { String n = a.text(); String vList = a.attr(&quot;href&quot;); String v = &quot;&quot;; if (name.contains(&quot;剧情&quot;)) { v = vList.split(&quot;/&quot;)[3]; } if (name.contains(&quot;年代&quot;)) { v = vList.split(&quot;/&quot;)[2]; } if (name.contains(&quot;地区&quot;)) { v = vList.split(&quot;/&quot;)[4]; } filterValues.add(new Filter.Value(n, v)); } filterTemp.add(new Filter(key, name, filterValues)); } filters.put(typeIds.get(i), filterTemp); } return Result.string(classes, list, filters); } @Override public String categoryContent(String tid, String pg, boolean filter, HashMap<String, String> extend) throws Exception { HashMap<String, String> ext = new HashMap<>(); if (extend != null &amp;&amp; extend.size() > 0) ext.putAll(extend); String cla = ext.get(&quot;按剧情&quot;) == null ? &quot;0&quot; : ext.get(&quot;按剧情&quot;); String area = ext.get(&quot;按地区&quot;) == null ? &quot;all&quot; : ext.get(&quot;按地区&quot;); String year = ext.get(&quot;按年代&quot;) == null ? &quot;0&quot; : ext.get(&quot;按年代&quot;); String cates = cateUrl + String.format(&quot;action=%s&amp;page=%s&amp;year=%s&amp;area=%s&amp;class=%s&amp;dect=0&amp;id=&quot;, tid, pg, year,area, cla); Document doc = Jsoup.parse(OkHttp.string(cates, getHeader())); List<Vod> list = new ArrayList<>(); for (Element li : doc.select(&quot;li&quot;)) { String vid = siteUrl + li.select(&quot;a&quot;).attr(&quot;href&quot;); String name = li.select(&quot;a&quot;).attr(&quot;title&quot;); String pic = li.select(&quot;img&quot;).attr(&quot;data-original&quot;); String remark = li.select(&quot;.name&quot;).text(); list.add(new Vod(vid, name, pic, remark)); } return Result.string(list); } @Override public String detailContent(List<String> ids) throws Exception { Document doc = Jsoup.parse(OkHttp.string(ids.get(0), getHeader())); StringBuilder vod_play_url = new StringBuilder(); StringBuilder vod_play_from = new StringBuilder(); Elements titles = doc.select(&quot;div.pfrom&quot;).select(&quot;ul&quot;).select(&quot;li[id^=tab]&quot;); Elements lists = doc.select(&quot;div.url&quot;).select(&quot;ul.urlli&quot;).select(&quot;ul&quot;); for (int i = 0; i < titles.size(); i++) { Element li = titles.get(i); vod_play_from.append(li.text()); if (i != titles.size() -1) { vod_play_from.append(&quot;$$$&quot;); } } for (int i = 0; i < lists.size(); i++) { if (i + 1 > titles.size()) { continue; } Element ul = lists.get(i); Elements liList = ul.select(&quot;li&quot;); for (int j = 0; j < liList.size(); j++) { Element li = liList.get(j); String name = li.select(&quot;a&quot;).text(); String url = siteUrl + li.select(&quot;a&quot;).attr(&quot;href&quot;); if (j != liList.size() - 1) { vod_play_url.append(name).append(&quot;$&quot;).append(url).append(&quot;#&quot;); } else { vod_play_url.append(name).append(&quot;$&quot;).append(url); } } if (i != titles.size() -1) { vod_play_url.append(&quot;$$$&quot;); } } String title = doc.select(&quot;dt.name&quot;).text(); Elements videoInfo = doc.select(&quot;div.info&quot;).eq(0).select(&quot;dl&quot;).select(&quot;dd&quot;); String remark = &quot;&quot;; String typeName = &quot;&quot;; String actor = &quot;&quot;; String director = &quot;&quot;; String year = &quot;&quot;; for (int j = 0; j < videoInfo.size(); j++) { Element div = videoInfo.get(j); String span = div.select(&quot;b&quot;).text(); String text = div.text(); if (span.contains(&quot;状态&quot;)) { remark = text; } if (span.contains(&quot;类型&quot;)) { typeName = text; } if (span.contains(&quot;主演&quot;)) { actor = text; } if (span.contains(&quot;导演&quot;)) { director = text; } if (span.contains(&quot;年代&quot;)) { year = text; } } String brief = doc.select(&quot;div.article-content&quot;).select(&quot;p&quot;).text(); Vod vod = new Vod(); vod.setVodId(ids.get(0)); vod.setVodYear(year); vod.setVodName(title); vod.setVodActor(actor); vod.setVodRemarks(remark); vod.setVodContent(brief); vod.setVodDirector(director); vod.setTypeName(typeName); vod.setVodPlayFrom(vod_play_from.toString()); vod.setVodPlayUrl(vod_play_url.toString()); return Result.string(vod); } @Override public String searchContent(String key, boolean quick) throws Exception { String url = searchUrl + URLEncoder.encode(key); String json = OkHttp.string(url, getHeader()); JSONArray objects = JSONArray.parseArray(json); List<Vod> list = new ArrayList<>(); for (int j = 0; j < objects.size(); j++) { JSONObject vod = (JSONObject)objects.get(j); String vid = siteUrl + vod.getString(&quot;url&quot;); String name = vod.getString(&quot;title&quot;); String pic = vod.getString(&quot;thumb&quot;); String remark = vod.getString(&quot;area&quot;); list.add(new Vod(vid, name, pic, remark)); } return Result.string(list); } @Override public String playerContent(String flag, String id, List<String> vipFlags) throws Exception { Matcher matcher0 = Pattern.compile(&quot;/(\\d+).html&quot;).matcher(id); String pid = matcher0.find() ? matcher0.group(1) : &quot;&quot;; String content = OkHttp.string(id, getHeader()); Matcher matcher1 = Pattern.compile(&quot;src=\&quot;(.*?)\&quot;></script><body>&quot;).matcher(content); String js = matcher1.find() ? matcher1.group(1) : &quot;&quot;; String urls = OkHttp.string(js, getHeader()); Matcher matcher2 = Pattern.compile(&quot;playarr_(.*?)\\[&quot; + pid + &quot;\\]=\&quot;(.*?.m3u8),-1,&quot;).matcher(urls); String realUrl = matcher2.find() ? matcher2.group(2) : &quot;&quot;; return Result.get().url(realUrl).header(getHeader()).string(); } }请将当前代码中的特殊符号转为正常标点
最新发布
09-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值