webapi-2 接口参数
1. 实例
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Net.Http;
- using System.Web.Http;
- using wxweb.Areas.API.Models;
- namespace wxweb.Areas.API.Controllers
- {
- public class ProductController : ApiController
- {
- Product[] products = new Product[]
- {
- new Product { Id = , Name = "Tomato Soup", Category = "Groceries", Price = },
- new Product { Id = , Name = "Yo-yo", Category = "Toys", Price = 3.75M },
- new Product { Id = , Name = "Hammer", Category = "Hardware", Price = 16.99M }
- };
- Product[] products_post = new Product[]
- {
- new Product { Id = , Name = "name01", Category = "Category01", Price = },
- new Product { Id = , Name = "name02", Category = "Category02", Price = 20M },
- new Product { Id = , Name = "name03", Category = "Category03", Price = 30M }
- };
- /// <summary>
- /// get 无参数传参
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- public IEnumerable<Product> GetAllProducts()
- {
- return products;
- }
- /// <summary>
- /// get 单参数传参
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [Route("api/Product/GetProductById")]
- [HttpGet]
- public IHttpActionResult GetProductById(string id)
- {
- var product = products.FirstOrDefault((p) => p.Id == Convert.ToInt32(id));
- if (product == null)
- {
- return NotFound();
- }
- return Ok(product);
- }
- /// <summary>
- /// get多参数传参
- /// </summary>
- /// <param name="id"></param>
- /// <param name="name"></param>
- /// <returns></returns>
- [HttpGet]
- public string para_get_base(string id,string name)
- {
- return "id:"+id+" name:"+name;
- }
- /// <summary>
- /// get form传参
- /// </summary>
- /// <param name="p"></param>
- /// <returns></returns>
- [Route("api/Product/para_get_form")]
- [HttpGet]
- public string para_get_form([FromUri]Product p)
- {
- return "p.Name:" + p.Name + " p.Price:" + p.Price;
- }
- /// <summary>
- /// post 无参数传参
- /// </summary>
- /// <returns></returns>
- [Route("api/Product/GetProducts")]
- [HttpPost]
- public IEnumerable<Product> GetProducts()
- {
- return products_post;
- }
- /// <summary>
- /// post 单个参数传参
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [Route("api/Product/GetProduct")]
- [HttpPost]
- public IHttpActionResult GetProduct([FromBody]string id)
- {
- var product = products_post.FirstOrDefault((p) => p.Id ==Convert.ToInt32( id));
- if (product == null)
- {
- return NotFound();
- }
- return Ok(product);
- }
- /// <summary>
- /// post 多参数传参
- /// </summary>
- /// <param name="obj"></param>
- /// <returns></returns>
- [Route("api/Product/para_post_base")]
- [HttpPost]
- public string para_post_base(dynamic obj)
- {
- string id = obj["id"].ToString();
- string name = obj["name"].ToString();
- return "id:" + id + " name:" + name;
- }
- /// <summary>
- /// post form传参
- /// </summary>
- /// <param name="p"></param>
- /// <returns></returns>
- [Route("api/Product/para_post_form")]
- [HttpPost]
- public string para_post_form(Product p)
- {
- return "p.Name:" + p.Name + " p.Price:" + p.Price;
- }
- /// <summary>
- /// post base+form传参
- /// </summary>
- /// <param name="p"></param>
- /// <returns></returns>
- [Route("api/Product/para_post_baseform")]
- [HttpPost]
- public string para_post_baseform(dynamic obj)
- {
- var parapost = Convert.ToString(obj.parapost);
- Product p = Newtonsoft.Json.JsonConvert.DeserializeObject<Product>(Convert.ToString(obj.formdata));
- return "parapost:"+parapost+ " p.Name:" + p.Name + " p.Price:" + p.Price;
- }
- /// <summary>
- /// post 数组参数
- /// </summary>
- /// <param name="ids"></param>
- /// <returns></returns>
- [Route("api/Product/post_array")]
- [HttpPost]
- public string post_array(string[] ids)
- {
- string result = "";
- for (int i = ; i < ids.Length; i++) {
- result += " :" + ids[i];
- }
- return result;
- }
- /// <summary>
- /// post 实体数组参数
- /// </summary>
- /// <param name="ids"></param>
- /// <returns></returns>
- [Route("api/Product/post_ojblist")]
- [HttpPost]
- public string post_ojblist(List<Product> plist)
- {
- string result = "";
- for (int i = ; i < plist.Count; i++)
- {
- result +=" <br/>||"+i+ ":name:" + plist[i].Name+" price:"+plist[i].Price;
- }
- return result;
- }
- }
- }
webapi
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- namespace wxweb.Areas.API.Models
- {
- public class Product
- {
- public int Id { get; set; }
- public string Name { get; set; }
- public string Category { get; set; }
- public decimal Price { get; set; }
- }
- }
实体类
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>Product App</title>
- </head>
- <body>
- <div>
- <h2>All Products from get Method</h2>
- <ul id="products" />
- </div>
- <div>
- <h2>Search by ID from get Method</h2>
- <input type="text" id="prodId" size="5" />
- <input type="button" value="Search" onclick="find();" />
- <p id="product" />
- </div>
- <div style="border-top:1px solid #ccc;">
- <h2>All Products from post Method</h2>
- <ul id="products_post" />
- </div>
- <div>
- <h2>Search by ID from post Method</h2>
- <input type="text" id="prodId_post" size="5" />
- <input type="button" value="Search" onclick="findpost();" />
- <p id="product_post" />
- </div>
- <div style="border-top:2px solid #ccc;">
- <h3>多参数传参</h3>
- id:<input type="text" id="get_id" name="=get_id" /><br />
- name:<input type="text" id="get_name" name="=get_name" /><br />
- <input type="button" value="get传参" onclick="para_get_base()" /><br />
- <span>get方式api调用结果</span> <span id="get_result"></span><br />
- <input type="button" value="post传参" onclick="para_post_base()" /><br />
- <span>post方式api调用结果</span><span id="get_result_post"></span><br />
- </div>
- <div style="border-top:2px solid #ccc;">
- <h3>实体传参</h3>
- <form id="form1">
- base:<input type="text" id="parapost"><br />
- Id:<input type="text" id="Id" name="Id" /><br />
- Name:<input type="text" id="Name" name="Name" /><br />
- Category:<input type="text" id="Category" name="Category" /><br />
- Price:<input type="number" id="Price" name="Price" /><br />
- </form>
- <input type="button" value="get form传参" onclick="para_get_form()" /><br />
- <span>get方式api调用结果</span> <span id="get_result_form"></span><br />
- <input type="button" value="post form传参" onclick="para_post_form()" /><br />
- <span>post方式api调用结果</span> <span id="get_result_form_post"></span><br />
- <input type="button" value="post base+form传参" onclick="para_post_baseform()" /><br />
- <span>post base+form方式api调用结果</span> <span id="get_result_baseform_post"></span><br />
- </div>
- <div style="border-top:2px solid #ccc;">
- <h3>数组传参</h3>
- <input type="button" value="post数组传参" onclick="post_array()" /><br />
- <span>post方式api调用结果</span><span id="post_array"></span><br />
- </div>
- <div style="border-top:2px solid #ccc;">
- <h3>实体集合</h3>
- <input type="button" value="post实体集合" onclick="post_ojblist()" /><br />
- <span>post方式api调用结果</span><span id="post_ojblist"></span><br />
- </div>
- <div style="margin-bottom:100px;"></div>
- <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.0.3.min.js"></script>
- <script src="../Scripts/jquery.serializeObject.js"></script>
- <script type="text/javascript">
- $(document).ready(function () {
- var uri = '/api/Product';
- var para = '';
- //get方式获取
- $.get(uri, para,
- function (data) {
- $.each(data, function (key, item) {
- $('<li>', { text: formatItem(item) }).appendTo($('#products'));
- });
- })
- var uripost = '/api/Product/GetProducts';
- //post方式获取
- $.post(uripost, para,
- function (data) {
- $.each(data, function (key, item) {
- $('<li>', { text: formatItem(item) }).appendTo($('#products_post'));
- });
- })
- });
- function formatItem(item) {
- return item.Name + ': $' + item.Price;
- }
- //使用get方式 单参数查询
- function find() {
- var uri = '/api/Product/GetProductById';
- var id = $('#prodId').val();
- var para = { 'id': id };
- //var uri = '';
- $.get(uri, para,
- function (data) {
- $('#product').text(formatItem(data));
- })
- }
- //使用post方式 单参数查询
- function findpost() {
- var uri = '/api/Product/GetProduct';
- var id = $('#prodId_post').val();
- var para = { '': id };//注意传递参数的参数名称,填''
- //var uri = '';
- $.post(uri, para,
- function (data) {
- $('#product_post').text(formatItem(data));
- })
- }
- //get方式多参数传参
- function para_get_base() {
- var uri = '/api/Product';
- var id = $('#get_id').val();
- var name = $('#get_name').val();
- var para = { id: id, name: name };
- $.ajax({
- url: uri,
- type: 'get',
- async: true,
- data: para,
- dataType: 'text',
- success: function (r) {
- $('#get_result').html(r);
- }, error: function (r) {
- console.log(r);
- }
- });
- }
- //post方式多参数传参
- function para_post_base() {
- var uri = '/api/Product/para_post_base';
- var id = $('#get_id').val();
- var name = $('#get_name').val();
- var para = { id: id, name: name };
- para = JSON.stringify(para);//js对象转化为字符传递
- $.ajax({
- url: uri,
- type: 'post',
- async: true,
- data: para,
- dataType: 'text',
- contentType: "application/json",
- success: function (r) {
- $('#get_result_post').html(r);
- }, error: function (r) {
- console.log(r);
- }
- });
- }
- //get方式传递form参数
- function para_get_form() {
- var uri = '/api/Product/para_get_form';
- //参数方式1,借助serializeObject 将form序列化为json对象
- var para = $('#form1').serializeObject();
- //参数方式2,依次写出每一个参数值
- var para2 = { Id: $('#Id').val(), Name: $('#Name').val(), Category: $('#Category').val(), Price: $('#Price').val() };//参数方式2,
- $.ajax({
- url: uri,
- type: 'get',
- async: true,
- data: para,
- contentType: "application/json",
- dataType: 'text',
- success: function (r) {
- $('#get_result_form').html(r);
- }, error: function (r) {
- alert(r);
- }
- });
- }
- //post方式传递form参数
- function para_post_form() {
- var uri = '/api/Product/para_post_form';
- //参数方式1,借助serializeObject 将form序列化为json对象
- var para = $('#form1').serializeObject();
- //参数方式2,依次写出每一个参数值
- var para2 = { Id: $('#Id').val(), Name: $('#Name').val(), Category: $('#Category').val(), Price: $('#Price').val() };//参数方式2,
- $.ajax({
- url: uri,
- type: 'post',
- async: true,
- data: para,
- dataType: 'text',
- success: function (r) {
- $('#get_result_form_post').html(r);
- }, error: function (r) {
- alert(r);
- }
- });
- }
- //post方式传递form参数
- function para_post_baseform() {
- var uri = '/api/Product/para_post_baseform';
- //参数方式1,借助serializeObject 将form序列化为json对象
- var formdata = $('#form1').serializeObject();
- var para = JSON.stringify({ parapost: $('#parapost').val(), formdata: formdata })
- $.ajax({
- url: uri,
- type: 'post',
- async: true,
- data: para,
- dataType: 'text',
- contentType: "application/json",
- success: function (r) {
- $('#get_result_baseform_post').html(r);
- }, error: function (r) {
- alert(r);
- }
- });
- }
- function post_array() {
- var arr = ["1", "2", "3", "4"];
- var para = JSON.stringify(arr);
- var uri = '/api/Product/post_array';
- $.ajax({
- type: "post",
- url: uri,
- contentType: 'application/json',
- data: para,
- dataType: 'text',
- success: function (data) {
- $('#post_array').html(data);
- },
- error: function (data) {
- console.log(data);
- }
- });
- }
- function post_ojblist() {
- var arr = [
- { Id: 1, Name: "Jim", Category: "001", Price:10 },
- { Id: 2, Name: "jack", Category: "002", Price: 20 },
- { Id: 3, Name: "tom", Category: "003", Price: 30 }
- ];
- var para = JSON.stringify(arr);
- var uri = '/api/Product/post_ojblist';
- $.ajax({
- type: "post",
- url: uri,
- contentType: 'application/json',
- data: para,
- dataType: 'text',
- success: function (data, status) {
- if (status) {
- $('#post_ojblist').html(data);
- } else {
- console.log(data);
- }
- }, error: function (data) {
- console.log(data);
- }
- });
- }
- </script>
- </body>
- </html>
html文件
- //
- // Use internal $.serializeArray to get list of form elements which is
- // consistent with $.serialize
- //
- // From version 2.0.0, $.serializeObject will stop converting [name] values
- // to camelCase format. This is *consistent* with other serialize methods:
- //
- // - $.serialize
- // - $.serializeArray
- //
- // If you require camel casing, you can either download version 1.0.4 or map
- // them yourself.
- //
- (function($){
- $.fn.serializeObject = function () {
- "use strict";
- var result = {};
- var extend = function (i, element) {
- var node = result[element.name];
- // If node with same name exists already, need to convert it to an array as it
- // is a multi-value field (i.e., checkboxes)
- if ('undefined' !== typeof node && node !== null) {
- if ($.isArray(node)) {
- node.push(element.value);
- } else {
- result[element.name] = [node, element.value];
- }
- } else {
- result[element.name] = element.value;
- }
- };
- $.each(this.serializeArray(), extend);
- return result;
- };
- })(jQuery);
jquery.serializeObject.js
2. get 请求
1>:实体作为参数调用时,前台的实体参数无法直接传递到后台,需在webapi中对实体参数加上[FromUri]特性说明。
这是因为通过get方式传递的参数都是通过Request URL传递到后台的,则FromUri 给api说明 参数是从Request URL中获取到的。
如下:
- /// <summary>
- /// get form传参
- /// </summary>
- /// <param name="p"></param>
- /// <returns></returns>
- [Route("api/Product/para_get_form")]
- [HttpGet]
- public string para_get_form([FromUri]Product p)
- {
- return "p.Name:" + p.Name + " p.Price:" + p.Price;
- }
get form传参 api
- //get方式传递form参数
- function para_get_form() {
- var uri = '/api/Product/para_get_form';
- //参数方式1,借助serializeObject 将form序列化为json对象
- var para = $('#form1').serializeObject();
- //参数方式2,依次写出每一个参数值
- var para2 = { Id: $('#Id').val(), Name: $('#Name').val(), Category: $('#Category').val(), Price: $('#Price').val() };//参数方式2,
- $.ajax({
- url: uri,
- type: 'get',
- async: true,
- data: para,
- contentType: "application/json",
- dataType: 'text',
- success: function (r) {
- $('#get_result_form').html(r);
- }, error: function (r) {
- alert(r);
- }
- });
- }
get form传参 js调用
2> 如果不想通过[FromUri]特性说明的方式进行传递实体,也可以使用把实体先序列化在反序列化的方式传递。
- $.ajax({
- type: "get",
- url: "http://localhost:27221/api/Charging/GetByModel",
- contentType: "application/json",
- data: { strQuery: JSON.stringify({ ID: "1", NAME: "Jim", CREATETIME: "1988-09-11" }) },
- success: function (data, status) {
- if (status == "success") {
- $("#div_test").html(data);
- }
- }
- });
- [HttpGet]
- public string GetByModel(string strQuery)
- {
- TB_CHARGING oData = Newtonsoft.Json.JsonConvert.DeserializeObject<TB_CHARGING>(strQuery);
- return "ChargingData" + oData.ID;
- }
get 实体传参 通过序列化的方式
get 方式总结
(1)Get参数传递的本质是url字符串拼接;
(2)url字符串长度受限制;
(3)Get参数传递在Http请求头部传递,而不支持Request-Body传递;
(4)Get类型的方法支持参数为基本类型,不支持实体类型;
(5)Get类型的方法命名,应尽量采用“Get+方法名”的命名方式,且习惯性地在方法前加上[HttpGet特性];
(6)实参与形参的匹配,遵循路由规则;
(7)Get对应DB的Select操作,从这一点来理解,就知道为什么Http不支持实体对象传递的合理性了,因为一般情况,我们都是通过简单的字段查询信息(对应基本类型),
如ID号,用户名等,而不会通过一个实体查询数据;
3 post 请求
1> post 单参数请求
我们一般的通过url取参数的机制是键值对,即某一个key等于某一个value,而这里的FromBody和我们一般通过url取参数的机制则不同,它的机制是=value,没有key的概念,并且如果你写了key(比如你的ajax参数写的{id:"1"}),后台反而得到的id等于null。
- //使用post方式 单参数查询
- function findpost() {
- var uri = '/api/Product/GetProduct';
- var id = $('#prodId_post').val();
- var para = { '': id };//注意传递参数的参数名称,填''
- //var uri = '';
- $.post(uri, para,
- function (data) {
- $('#product_post').text(formatItem(data));
- })
- }
- /// <summary>
- /// post 单个参数传参
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [Route("api/Product/GetProduct")]
- [HttpPost]
- public IHttpActionResult GetProduct([FromBody]string id)
- {
- var product = products_post.FirstOrDefault((p) => p.Id ==Convert.ToInt32( id));
- if (product == null)
- {
- return NotFound();
- }
- return Ok(product);
- }
post 单参数请求
2> 多参数请求
post方式是不支持多参数方式请求的,为了传递多参数我们可以采用其他的方式。
比如,在后台建立对象实体,然后将整个实体作为对象传递,
- //post方式传递form参数
- function para_post_form() {
- var uri = '/api/Product/para_post_form';
- //参数方式1,借助serializeObject 将form序列化为json对象
- var para = $('#form1').serializeObject();
- //参数方式2,依次写出每一个参数值
- var para2 = { Id: $('#Id').val(), Name: $('#Name').val(), Category: $('#Category').val(), Price: $('#Price').val() };//参数方式2,
- $.ajax({
- url: uri,
- type: 'post',
- async: true,
- data: para,
- dataType: 'text',
- success: function (r) {
- $('#get_result_form_post').html(r);
- }, error: function (r) {
- alert(r);
- }
- });
- }
- /// <summary>
- /// post form传参
- /// </summary>
- /// <param name="p"></param>
- /// <returns></returns>
- [Route("api/Product/para_post_form")]
- [HttpPost]
- public string para_post_form(Product p)
- {
- return "p.Name:" + p.Name + " p.Price:" + p.Price;
- }
post 通过对象实体传递多参数
html页面中如果使用form序列化的方式,可以调用serializeObject.js的方法得到json对象。
比如,使用dynamic参数,动态的获取所需要的参数。
- //post方式多参数传参
- function para_post_base() {
- var uri = '/api/Product/para_post_base';
- var id = $('#get_id').val();
- var name = $('#get_name').val();
- var para = { id: id, name: name };
- para = JSON.stringify(para);//js对象转化为字符传递
- $.ajax({
- url: uri,
- type: 'post',
- async: true,
- data: para,
- dataType: 'text',
- contentType: "application/json",
- success: function (r) {
- $('#get_result_post').html(r);
- }, error: function (r) {
- console.log(r);
- }
- });
- }
- /// <summary>
- /// post 多参数传参
- /// </summary>
- /// <param name="obj"></param>
- /// <returns></returns>
- [Route("api/Product/para_post_base")]
- [HttpPost]
- public string para_post_base(dynamic obj)
- {
- string id = obj["id"].ToString();
- string name = obj["name"].ToString();
- return "id:" + id + " name:" + name;
- }
post 通过dynamic 传递多参数
post 方式总结
(1)Post参数传递本身是在Request-Body内传递,而Get参数传递本质是url拼接;
(2)Post参数传递不是key/value形式,而Get参数是key/value形式;
(3)Post传递参数时,无论是单个参数还是对象,均借助[FromBody]特性(当然,某些情况去掉[FromBody]特性也可把值传递进去,但为了规范化,尽量加上该特性);
(4)Post没长度限制,而Get有长度限制(一般为1024b);
(5)Post相对Get,较安全;
(6)Post操作相当于DB的Insert操作;
4 总结
1.虽然HTTP请求方法有20多种,常用的大致为4种,即Get,Post,Put,Delete(当然,像Trace,Head等也常用);
2.Get,Post,Put,Delete分别对应DB的Select,Insert,Update和Delete操作;
3.WebApi参数类型,大致分为基本数据类类型和对象数据类型(当然你也可以理解为抽象数据类型);
4.研究WebApi参数传递,只需研究Get和Post即可,因为其他http方法参数传递基本都是有这两种组合而成(如Put有Get和Post组合而成),或者相似(如Delete与Get相似);
5.对于控制器方法,尽量参照规范格式写,如在相应控制器方法上加上对应的htt请求(Get对应[HttpGet],Post对应[HttpPost]),方法名尽量采用“Http请类型+方法名”格式(如Get请求,建议采用Get+MethodName;Post请求对应Post+MethodName);
6.WebApi参数请求,大致分为两大类型,即Request-url和Request-body;
引用:
https://www.cnblogs.com/landeanfen/p/5337072.html#_label3
http://www.cnblogs.com/wangjiming/p/8378108.html
webapi-2 接口参数的更多相关文章
- WebApi 接口参数详解
WebApi 接口参数不再困惑:传参详解 阅读目录 一.get请求 1.基础类型参数 2.实体作为参数 3.数组作为参数 4.“怪异”的get请求 二.post请求 1.基础类型参数 2.实体作为 ...
- [置顶]
webapi token、参数签名是如何生成的
一个问题 在这里我想问大家一句,如果你向一个刚刚接触.net web后端程序开发的同学(别人刚刚也就学了webform的request,response,会提交表单的这种刚接触不久的同学),你怎么去解 ...
- webapi token、参数签名是如何生成的(转载)
API接口保障安全性原则:1.有调用者身份2.请求的唯一性3.请求的参数不能被篡改4.请求的有效时间 在刚接触接口开发时,可能脑子里压根就没有这个接口调用安全性的原则,但常识性的经验告诉我们,每一个请 ...
- 如何写出安全的API接口?接口参数加密签名设计思路
开发中经常用到接口,尤其是在面向服务的soa架构中,数据交互全是用的接口. 几年以前我认为,我写个接口,不向任何人告知我的接口地址,我的接口就是安全的,现在回想真是too young,too simp ...
- Asp.Net Mvc4 Webapi Request获取参数
最近用mvc4中的WEBAPI,发现接收参数不是很方便,跟传统的request.querystring和request.form有很大区别,在网上搜了一大圈,各种方案都有,但不是太详细,于是跟踪Act ...
- WebApi 方法的参数类型总结。
1:[HttpGet] ①:get方法之无参数. [HttpGet] public IHttpActionResult GetStudentInfor() { List<StudentMode ...
- Asp.Net WebAPI配置接口返回数据类型为Json格式
Asp.Net WebAPI配置接口返回数据类型为Json格式 一.默认情况下WebApi 对于没有指定请求数据类型类型的请求,返回数据类型为Xml格式 例如:从浏览器直接输入地址,或者默认的XM ...
- c# WebApi之接口返回类型详解
c# WebApi之接口返回类型详解 https://blog.csdn.net/lwpoor123/article/details/78644998
- mybatis 多个接口参数的注解使用方式(@Param)
目录 1 简介 1.1 单参数 1.2 多参数 2 多个接口参数的两种使用方式 2.1 Map 方法(不推荐) 2.1.1 创建接口方法 2.1.2 配置对应的SQL 2.1.3 调用 2.2 @Pa ...
- ASP.NET WebApi服务接口如何防止重复请求实现HTTP幂等性
一.背景描述与课程介绍 明人不说暗话,跟着阿笨一起玩WebApi.在我们平时开发项目中可能会出现下面这些情况; 1).由于用户误操作,多次点击网页表单提交按钮.由于网速等原因造成页面卡顿,用户重复刷新 ...
随机推荐
- Gevent-自动挡切换
Gevent: Gevent 是一个第三方库,可以轻松通过gevent实现并发同步或异步编程,在gevent中用到的主要模式是Greenlet, 它是以C扩展模块形式接入Python的轻量级协程. G ...
- 【以前的空间】bzoj 1052 [HAOI2007]覆盖问题
这道题的思路挺简单的……就是可以证明如果要覆盖一个区域内的点,那么一定有一个正方形在这“区域内的点所围成的最大矩形的四个角中的一个”(不要吐槽很多的“的”……),对于长度r是否可以覆盖整个区域内的点, ...
- POJ3177:Redundant Paths——题解
http://poj.org/problem?id=3177 明显要求桥的一道题. (因为有桥就说明只能从那一条路走,换句话说就是只有一种方法) 求完桥后按照结论(加几条边成双连通图的结论,不会请ba ...
- BZOJ1068:[SCOI2007]压缩——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=1068 Description 给一个由小写字母组成的字符串,我们可以用一种简单的方法来压缩其中的重复 ...
- [bzoj] 1030 文本生成器 || AC自动机+dp
原题 给出n个字符串,求随机生成一个m长度的字符串,有多少个是可辨识的(即出现了n个字符串中的任意字符串) 正难则反 求有多少个不可辨识的,26^m-不可辨识即为答案 f[i][j]表示填到第i个字符 ...
- 洛谷 U32911 道路维护 解题报告
U32911 道路维护 题目背景 最近很多人投诉说C国的道路破损程度太大,以至于无法通行. C国的政府很重视这件事,但是最近财政有点紧,不可能将所有的道路都进行维护,所以他们决定按照下述方案进行维护. ...
- UVA.129 Krypton Factor (搜索+暴力)
UVA.129 Krypton Factor (搜索+暴力) 题意分析 搜索的策略是:优先找长串,若长串不合法,则回溯,继续找到合法串,直到找到所求合法串的编号,输出即可. 注意的地方就是合法串的判断 ...
- redux的bindActionCreators
bindActionCreators是redux的一个API,作用是将单个或多个ActionCreator转化为dispatch(action)的函数集合形式. 开发者不用再手动dispatch(ac ...
- 【Codeforces 506E】Mr.Kitayuta’s Gift&&【BZOJ 4214】黄昏下的礼物 dp转有限状态自动机+矩阵乘法优化
神题……胡乱讲述一下思维过程……首先,读懂题.然后,转化问题为构造一个长度为|T|+n的字符串,使其内含有T这个子序列.之后,想到一个简单的dp.由于是回文串,我们就增量构造半个回文串,设f(i,j, ...
- NDK plugin来构建JNI项目(相对于手动构建)
http://blog.csdn.net/codezjx/article/details/8879670 1.添加ndk环境支持 Android Tools -> Add Native Supp ...